用指针实现,不懂如何运用指针

用函数求字符串的长度,在main函数中输入字符串,并输出其长度

指针其实和数组差不多哦,你定义一个char类型指针,然后当做字符数组用就好了,你可以尝试一下,如果还是不会的话,你可以问我。

#include <stdio.h>

unsigned int strlen(const char *p) 
{
    const char *s = p;
    while (*p) p++;
    return (unsigned int)(p - s);
}

int main()
{
    const char* str = "adsfasdfdasdf";
    printf("%u",strlen(str));
    return 0;
}