第一次写,有点捞。(比心)
#include <stdio.h>
#include <assert.h>
int my_strncmp(const char* p1, const char* p2, int sz)
{
assert(p1 && p2);//保证p1和p2不是空指针
while (--sz && (*p1 == *p2))//sz的数字必须大于0,p1与p2里面的值相等且不能是'\0';
{
p1++;
p2++;//查看它们的下一个字符
}
return *p1 - *p2;//返回两个字符的ASCLL的差
}