传入字符串,计算字符串长度(用指针实现)

int strlen(char *s)
{
    int i=0;
    while(*s!='\0')
    {
        i++;
        s++;
    }
    return i;
}

void main()
{
    char str[100];
    int len;
    printf("please input your string:");
    gets(str);
    len=strlen(str);
    printf("the length of str is:%d\n",len);
}
posted @ 2016-03-28 08:20  phlsheji  阅读(739)  评论(0编辑  收藏  举报