strcmp自己写的出问题
程序:
#include <stdio.h>
#include <malloc.h>
int strcmp(char* p1, char* p2)
{
//while( (*p1!='\0') && (*p2!='\0') )
while( *p1 == *p2)
{
p1++;
p2++;
}
return *p1-*p2;
}
int main()
{
int res = 0;
res = strcmp("hello", "good");
printf("res=%d\n");
}
为什么结果都是0? printf
[解决办法]
你的输出没变量了
printf("res=%d\n");-》
printf("res=%d\n",res);