strcmp函数

strcmp函数比较两个字符串是否相等;

使用方法:

int strcmp ( const char * str1, const char * str2 );
举个例子,在网上看到的:

/* strcmp example */
#include <stdio.h>
#include <string.h>

int main ()
{
  char szKey[] = "apple";
  char szInput[80];
  do {
     printf ("Guess my favourite fruit? ");
     gets (szInput);
  } while (strcmp (szKey,szInput) != 0);
  puts ("Correct answer!");
  return 0;
}

结果:


posted @ 2012-05-29 20:02  应律  阅读(219)  评论(0)    收藏  举报