#include <stdio.h>
#include <string.h>
mylen(const char* s);
mycmp(const char* s1, const char* s2);
int main()
{
//strlen 的简单的练习
char arr[] = "hello world";
int str = strlen(arr);
printf("%d\n", str);
printf("%d\n", mylen(arr));
//strcmp 的简单的练习
char arr1[] = "HEllo";
char arr2[] = "He";
printf("%d\n", strcmp(arr1, arr2));
printf("%d\n", mycmp(arr1, arr2));
mycmp(arr1, arr2);
return 0;
}
mycmp(const char* s1, const char* s2)
{
int i = 0;
int count = 0;
while (s1 != '\0' && s1[i] == s2[i])
{
i++;
}
if (s1[i] > s2[i])
{
count = 1;
}
else if (s1[i] < s2[i])
{
count = -1;
}
else if (s1[i] == s2[i])
{
count = 0;
}
return count;
}
mylen(const char* s)
{
int count = 0;
while (s[count] != '\0')
{
count++;
}
return count;
}
7.14练习