编译运行范例,输出结果如下

$ gcc main.c && ./a.out
输入字符串: http://www.twle.cn/yufei/cexample-basic-index.html
你输入的字符串长度为: 50

不使用 strlen()

* file: main.c * author: 简单教程(www.twle.cn) #include <stdio.h> int main() char s[1000], i; printf("输入字符串: "); scanf("%s", s); for(i = 0; s[i] != '\0'; ++i); printf("你输入的字符串长度为: %d\n", i); return 0;

编译运行范例,输出结果如下

$ gcc main.c && ./a.out
输入字符串: http://www.twle.cn/yufei/cexample-basic-index.html
你输入的字符串长度为: 50