//
#include<stdio.h>
#include<ctype.h>
#define N 100
int main()
{
char ch[N];
int c=0,count=1;
printf("Please input string:\n");
gets(ch);
while(ch[c]!='\0')
{
if(!isgraph(ch[c])) //記錄除空格以外的所有可打印字符
{
count++;
}
c++;
}
printf("There are %d words in this paragraph\n",count); //該計數器記錄的是除空格以外的單詞數量
}
運行結果:
知識點:
1.使用字符處理函數在程序開頭必須包含頭文件”ctype.h”;
2.gets()用於輸入字符串;
3.字符的移位不能放在if()語句中。