#include <stdio.h> |
#include <string.h> |
#define MAX_STRING 200 |
int main( void ) { |
char str[MAX_STRING] = { 0 }; |
int i = 0; |
int length = 0; |
int count = 0; |
/* 打印原字符数组 */ |
puts ( "Input original String:" ); |
gets (str); |
length = strlen (str); |
/* 统计单词个数 */ |
for (i = 0; i < length; ++i) { |
if (str[i] != ' ' ) { /* 单词开始 */ |
++count; |
while ( ' ' != str[i] && '\0' != str[i]) /* 单词结束 */ |
++i; |
} |
} |
printf ( "There are %d words in \"%s\".\n" , count, str); |
return 0; |
} |
by: 发表于:2017-08-15 10:52:33 顶(0) | 踩(0) 回复
??
回复评论