#include <stdio.h>
#include <string.h>
int strcmp(const char *,const char *);
int main(){
int error;
char a[10]="abc";
char b[10]="abc";
error=strcmp(a,b);
if(error){
printf("no match\n");
return 0;
}
printf("ok\n");
return 0;
}
int strcmp(const char *s1,const char *s2){
while(*s1!='\0'){
if(*s1!=*s2){
return -1;
}
else{
s1++;
s2++;
}
}
return 0;
}
用strcmp函数来匹配两个字符串,不相等时输出no match
此时输出:
ok