The first printf gives output as -1, whereas the second printf gives output as -115.
#include<stdio.h>
#include<string.h>
int mystrcmp(char*s, char*t){
for(;*s==*t;s++,t++){
if(*s=='\0'){
return 0;
}
}
return (*s-*t);
}
int main()
{
char *y,*x="this";
y="thiss";
printf("%d\n\n",strcmp(x,y));
printf("%d",mystrcmp(x,y));
return 0;
}
I understand, that in my implementation, the code is calculating 0(ASCII of Null) - 's'(ASCII value 115). Can anyone please help me as to how I may exactly duplicate the working of strcmp function that is in string.h