改写string.h库函数
my_strncmp 字符串比较n个*/
#include <stdio.h>
/* my_strncmp 字符串比较n个*/
int my_strncmp(char * d, char * s, int n);
int main (int argc, char * argv[])
{
char * p1 = "abcd";
char * p2 = "abcd\0d";
printf("%d\n", my_strncmp(p1, p2,4));
return 0;
}
int my_strncmp(char * d, char * s, int n )
{
int i = 0;
while((*(d+i) != '\0' || * (s+i) != '\0') && i < n)
{
if( *(s+i) > *(d+i))
return 1;
if (* (s+i) < *(d + i) )
return -1;
i++;
}
return 0;
}