/*Using various string-handling functions*/ #include #include #include #define N 100 int main() { char *s1, *s2; //declare two strings s1 = malloc(N); //sizeof(char)=1 for all machines s2 = malloc(N); if (!s1 || !s2){ printf("Out of memory!\n"); return 1; } printf("Please enter s1 and s2:\n"); // gets(s1); // gets(s2); scanf("%s", s1); scanf("%s", s2); puts(s1); puts(s2); printf("Length of s1 and s2: %d %d\n", strlen(s1), strlen(s2)); printf("Comparing s1 and s2: "); if (!strcmp(s1, s2)) printf("They are equal\n"); else printf("They are NOT equal\n"); printf("Concatenating s2 onto the end of s1: "); strcat(s1, s2); printf("s1 = %s\n", s1); printf("Copying another string to s1: "); strcpy(s1, "This is a test.\n"); printf("s1 = %s", s1); if (strchr(s1, 'e')) printf("e is in s1\n"); if (strstr(s1, "test")) printf("found test in s1\n"); free(s1); //release allocated memory free(s2); return 0; }