/* This program tries to demonstrate some more facts about strings. */ #include #include int main( void ) { char s1[4] = " "; char s2[4]; int i; printf("Enter 2 identical strings, each of 3 characters or less.\n"); printf("Separate the strings by tabs or blanks.\n"); for (i = 0; i < 3; i += 1) { s2[i] = getchar(); if (s2[i] == EOF) break; } /* for */ scanf("%s", s1); if ( strcmp(s1, s2) == 0 ) { printf("s1 = %s equals s2 = %s\n", s1, s2); } else { printf("s1 = %s does not equal s2 = %s\n", s1, s2); } /* if */ if ( i < 3) { s2[++i] = '\0'; } else { s2[3] = '\0'; } /* if */ if ( strcmp(s1, s2) == 0 ) { printf("s1 = %s equals s2 = %s\n", s1, s2); } else { printf("s1 = %s does not equal s2 = %s\n", s1, s2); } /* if */ }