Second, there is a problem with your judgment condition The condition is changed to (*p == *q ) & & (*p ! = '0') & & (*q! = '0') At this point, enter the loop Execute: p + +, q + +;
while () outside the loop Execute the statement to ask for bad;
Suggestion!
Attached code:
#include<stdio.h>
int str(char* p1,char* p2)
{
while(*p1 && *p2 && *p1 == *p2)
{
p1++;
p2++;
}
return *p1 - *p2;
}
int main(void)
{
char a[100] = "abcdefg";
char b[100] = "abcdasd";
int ret = 0;
ret = str(a,b);
printf("%d\n",ret);
return 0;
}