读书人

linux c解决方法

发布时间: 2013-03-26 09:54:34 作者: rapoo

linux c
#include<stdio.h>
int main()
{
int count = 0;
int i = 0;
char ch[10];

printf("please input:\n");
scanf("%s",ch);

while(ch[i] != '\0' )
{
if(ch[i] == ' ')
{count++;
}
i++;
}
printf("\n the counts is %d\n",count);
return 0;
}我想知道为什么这个程序算不出空格的个数(在liunx下)

[解决办法]
scanf("%s",ch); 这个函数遇空格就停止读了。百度出来看看

读书人网 >C语言

热点推荐