编写一个程序,判断输入字符串中的字符个数,不能用strlen()函数(长度不超过100)

如题所述

#include <stdio.h>

int len(char *s)
{
    char *p;
    for(p=s;*p;++p);
    return p-s;
}

int main()
{
    printf("%d\n",len("Hello World"));

    return 0;
}

温馨提示:内容为网友见解,仅供参考
第1个回答  2018-06-03
    int i = 0;
    char a[100] = "Hello world!";
    while(a[i] != '\0')
    {
        i++;
    }
    printf("%d",i);

相似回答