在线工具 在线编程 在线白板 在线工具 在线编程 在线白板

C语言定义一个比较大的字符数组,然后从键盘进行初始化数组值,输出输入字符串的长度

以下为我自己写的,但是输出结果为0.
#include <stdio.h>
int main(void)
{
char ch[100]={};
int i=0,count=0;
scanf("%[^\n]",ch);
while(ch[i]=='\0')
{
count ++;
i ++;
}
printf("%d\n",count);

return 0;
}
最新回答
爱你让我明白

2024-09-10 07:47:46

#include <stdio.h>
int main(void)
{
char ch[100]={};
int i=0,count=0;
scanf("%s",ch);
while(ch[i]!='\0')
{
count ++;
i ++;
}
printf("%d\n",count);

return 0;
}