c语言实现strcmp和strlen、sizeof

来源:互联网 发布:oracle类似md5算法 编辑:程序博客网 时间:2024/04/26 05:56

include

include

include

include

define SIZEOF(value)((char )(&value + 1) - (char )&value)

int mystrlen(char *a)
{
int n = 0;
while(*a++ != ‘\0’)
n++;
return n;
}

int mystrcmp(const char *str1, const char *str2)
{
while (*str1 == *str2 && *str1 && *str2)
{
++str1;
++str2;
}
if (*str1 > *str2)
return 1;
else if(*str1 < *str2)
return -1;
else
return 0;
}

int main()
{
char a[] = “11”;
char b[] = “11”;
printf(“strlen == %d\n”, mystrlen(a));
printf(“sizeof == %d\n”, SIZEOF(a));
printf(“strcmp == %d”, mystrcmp(a, b));

return 0;

}

0 0
原创粉丝点击