/* 字符串的比较 */ |
#include <stdio.h> |
#define SIZE 256 |
int main( void ) { |
char str1[SIZE] = "\0" ; |
char str2[SIZE] = "\0" ; |
char * p1 = str1; |
char * p2 = str2; |
printf ( "Please input the first string:" ); |
gets (p1); |
printf ( "Please input the second string:" ); |
gets (p2); |
while (*p1 == *p2 && '\0' == *p1) { |
++p1; |
++p2; |
} |
if (*p1 == *p2) |
printf ( "They are same.\n" ); |
else if (*p1 > *p2) |
printf ( "The first one is larger than the second one.\n" ); |
else |
printf ( "The first one is smaller than the second one.\n" ); |
return 0; |
} |