size_t是 unsigned int
fgets会读入\n,用strcspn函数除去
assert判读指针是否为空指针,使用前要引头文件<assert.h>
#include <stdio.h>
#include <assert.h>
size_t mystrlen(const char* str)
{
assert(str);
size_t count = 0;
while (*str != '\0')
{
count++;
str++;
}
printf("%d", count);
return count;
}
int main()
{
char arr[1001];
fgets(arr,1001, stdin);
arr[strcspn(arr,"\n")] = 0;
mystrlen(arr);
return 0;
}