代码
// size_t strlen(const char *s);
#include <stdio.h>
#include <string.h>
#include <assert.h>
size_t mystrlen(const char *s)
{
assert(s != NULL);
int cnt = 0;
while(*s++ != '\0')
cnt++;
return cnt;
}
int main()
{
printf("strlen(\"hello\") = %lu\n",strlen("hello"));
printf("mystrlen(\"hello\") = %lu\n",mystrlen("hello"));
return 0;
}
执行
strlen("hello") = 5
mystrlen("hello") = 5