自己写一个strcmp函数。结果不太正确。
strcmp(char *p1,char *p2)
{
int i=0;
while(*(p1+i++)==*(p2+i++))
return (*(p1+i)-*(p2+i));
}
int main()
{
int m;
char str1[20],str2[20],*p1,*p2;
printf("input two stings:\n");
scanf("%s",str1);
scanf("%s",str2);
p1=&str1[0];
p2=&str2[0];
m=strcmp(p1,p2);
printf("result:%d\n",m);
return 0;
}
如题。当输入两个都是单个字符比较时。好像返回的值不正确。请指点一下。程序哪里有问题。谢谢
相关推荐
用一个函数实现两个字符串的比较,即自己写一个 strcmp 函数
用一个函数实现两个字符串的比较,即自己写一个 strcmp 函数
strcmp函数 strcmp函数 strcmp函数
strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strcmp函数strc
strcmp函数应用
用法:#include 功能:比较字符串s1和s2。 说明: 当s1<s2时,返回值s2时,返回值>0
输入两个字符串,编一个程序实现strcmp()函数
输入两个字符串,编一个程序实现strcmp()函数 #include #include #define N 100 main() { int i; char a[N],b[N]; printf("input a[] and b[]:\n"); gets(a); gets(b); for(i=0;ib[i]) {printf("a>b");break;} else if(a[i]a");break;} } if(i==N) printf("a==b"); }
C中strcmp,strcpy,strcat函数编写
该文档给出了详细的C中几个经典函数的编写,strcmp,strcpy,strcat函数,面试中经常会被要求编出来。


