c语言编程 输入一个字符串,统计其中空格的个数

如题所述

第1个回答  2013-12-19
char str[BUFSIE + 1] = {0};
int spaseCnt;

gets(str);
/*or
fgets(str,BUFSIZ, stdin);
str[ strchr(str,'\n') - str ] = '\0';
*/
spaseCnt = 0;
size_t i = 0;
while (str[i] != '\0') {
 if (isspase(str[i])) {
  ++spaseCnt;
 }
 ++i;
}
printf("空格数量:%d", spaseCnt);
第2个回答  2013-12-19
char myStr[100];
gets(myStr);
int count=0;
char* p=myStr;
while(p!='\0')
{
if(p==32)
count++;
p++;
}
printf("%d",count);本回答被网友采纳
第3个回答  2013-12-19

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网