C–六、字符串之strcmp
函数原型:
int strcmp(const char *s1,const char *s2);
#include <stdio.h>
#include <string.h>
#include <assert.h>
int myStrcmp(char *p1,char *p2){
assert(p1 != NULL || p2 != NULL);
int ret = 0;
while(*p1 && *p2 && (p1 == p2)){
p1++;
p2++;
}
if((int)*p1 > (int)*p2){
ret = 1;
}else{
ret = -1;
}
return ret;
}
int main(){
char *a = "helloworld.java";
char *b = "helloworld.c";
int ret = myStrcmp(a,b);
printf("%d",ret);
return 0;
}