计算单词数我想问问用这种方法计算单词数正确吗?但是如果遇到两个单词之间不止一个空格时。。计数就错误了,
计算单词数
我想问问用这种方法计算单词数正确吗?
但是如果遇到两个单词之间不止一个空格时。。计数就错误了,该怎么办?
- C/C++ code
#include<stdio.h>#include<string.h>#define LIM 80int main(void){ char str[LIM]; int ct=0,words=0; puts("Enter:"); gets(str); for(ct=0;ct<LIM;ct++) if(str[ct]==' '||str[ct]=='\0') words++; printf("There are %d words.\n",words); return 0;}[解决办法]
