Program1
Program1
a: "to get the length of a string, you use the strlen() function"
b: "To concatenate (combine) two strings, you can use the strcat() function
c: "To copy the value of one string to another, you can use the strcpy()"
d: "To compare two strings, you can use the strcmp() function." and other
related functions
#include <stdio.h>
int length = 0;
length++;
return length;
int i = 0;
i++;
}
int j = 0;
dest[i] = src[j];
i++;
j++;
dest[i] = '\0';
int i = 0;
dest[i] = src[i];
i++;
// Add null-terminator
dest[i] = '\0';
int i = 0;
// Compare the strings character by character
if (str1[i] != str2[i]) {
i++;
// If one string is shorter than the other, return the difference in length
int main() {
// Test data
str1[my_strlen(str1) - 1] = '\0';
str2[my_strlen(str2) - 1] = '\0';
my_strcpy(str4, str1);
if (result == 0) {
} else {
return 0;
#include <stdio.h>
// Function to get the length of a string int my_strlen(const char *str) { int
length = 0; while (str[length] != '\0') { length++; } return length; }
// Function to compare two strings int my_strcmp(const char *str1, const char
*str2) { while (*str1 != '\0' && *str2 != '\0') { if (*str1 != *str2) { return *str1
- *str2; // Return the difference between the first non-matching characters }
str1++; str2++; } return *str1 - *str2; // If one string is longer, this will return
the difference }
return 0;
}