2021-03-17
作者:互联网
改写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;
}
标签:strncmp,03,return,17,int,char,abcd,2021,my 来源: https://blog.csdn.net/Zhou_zilv/article/details/114915402