我的微信
运营不易,
感谢支持!
计算字符串长度。
#include <stdio.h> #include <string.h> int main() { char s[1000]; int len; printf("输入字符串: "); scanf("%s", s); len = strlen(s); printf("字符串长度: %d", len); return 0; }
输出结果为:
输入字符串: nowcoder 字符串长度: 6
#include <stdio.h> int main() { char s[1000], i; printf("输入字符串: "); scanf("%s", s); for(i = 0; s[i] != '\0'; ++i); printf("字符串长度: %d", i); return 0; }
输出结果为:
输入字符串: nowcoder 字符串长度: 8