1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #include <stdio.h> #include <string.h>
int main() { char str1[20] = "Hello"; char str2[] = "World";
char result[40]; strcpy(result, str1); strcat(result, " "); strcat(result, str2);
printf("Concatenated String: %s\n", result);
if (strcmp(str1, str2) == 0) { printf("str1 and str2 are equal.\n"); } else { printf("str1 and str2 are not equal.\n"); }
char *pos = strchr(result, 'W'); if (pos != NULL) { printf("Character 'W' found at position: %ld\n", pos - result); }
return 0; }
|