/*
* strcmp 字符串的比较
*/
#include <cstdio>
int strcmp ( const char * str1, const char * str2 ) {
while (*str1==*str2 && *str1!='\0')
++str1, ++str2;
return *str1-*str2;
}
int main ()
{
char key[] = "apple";
char buffer[80];
do {
printf ("Guess my favorite fruit? ");
fflush (stdout);
scanf ("%79s",buffer);
} while (strcmp (key,buffer) != 0);
puts ("Correct answer!");
return 0;
}
C 标准库 strcmp 函数的实现
最新推荐文章于 2022-03-09 20:03:42 发布