Posted on 2007-07-04 20:31
停留的风 阅读(266)
评论(0) 编辑 收藏 所属分类:
C语言学习历程
#include <stdio.h>
int equalStrings (const char s1[],const char s2[])
{
int i=0;
int areEqual;
while(s1[i]==s2[i]&&s1[i]!='\0'&&s2[i]!='\0')
i++;
if(s1[i]=='\0'&&s2[i]=='\0')
areEqual=1;
else
areEqual=0;
return areEqual;
}
int main(void)
{
int equalStrings (const char s1[],const char s2[]);
const char stra[]="string compare test";
const char strb[]="string";
printf("%i\n",equalStrings(stra,strb));
printf("%i\n",equalStrings(stra,stra));
printf("%i\n",equalStrings(strb,"string"));
return 0;
}
运行结果: