请用C语言设计一个程序:输入一个字符串,计算其长度。

如题所述

#include <stdio.h>
int main()
{
int n=0;
while(getchar()!='\n')
n++;
printf("%d",n);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-12-13
#include <stdio.h>
size_t strlen(const char *s)
{
char *ts =s;
for(; *ts; ts++)
;
return ts-s;
}
int main()
{
char s[100];

fgets(s, 100, stdin);
printf("lenth =%d", strlen(s));
getchar();

return 0;
}
第2个回答  2013-12-13
;char a[n];gets(a);puts(a);printf("长度是%d位",strlen(a))
相似回答
大家正在搜