标签:
#include <stdio.h>
#include <stdlib.h>
/*
输入一行字符串(单词和若干空格),
输出该行单词个数。
*/
int main(){
char ch, str[100];
int count = 0;
gets(str);
for (int j = 0; str[j] != ‘\0‘;++ j)
if ((str[j + 1] == ‘\0‘) && (str[j] != ‘ ‘)) //到达末尾且不为空格,单词数+1
count++;
else if ((str[j] != ‘ ‘) && (str[j + 1] == ‘ ‘)) //不为空格但下一字符为空格,单词数+1
count++;
printf("%d\n", count);
system("pause");
return 0;
}
标签:
原文地址:http://www.cnblogs.com/mutaohengheng/p/5108031.html