您的位置:首页 > 其它

编写函数,对标准输入进行扫描,并对“the”出现的次数进行计数。 进行比较时应区分大小写。认为一个单词有一个或多个空格字符分隔, 并且输入行在长度上不会超过100个字符,计数结果输出。

2015-01-22 15:11 751 查看
/****************************************
*  File Name  : string.c
*  Creat Data : 2015.1.22
*  Author     : ZY
*****************************************/

/*编写函数,对标准输入进行扫描,并对“the”出现的次数进行计数。
进行比较时应区分大小写。认为一个单词有一个或多个空格字符分隔,
并且输入行在长度上不会超过100个字符,计数结果输出。*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char const whitespace[] = "\n\r\f\t\v";
int main( void )
{
char string[101];
int count = 0;
//读取文本行直到发现EOF
while(gets(string))
{
char *word;
//从缓冲区提取单词,直到缓冲区内不再有单词
for( word = strtok( string , whitespace);word != NULL;word = strtok( NULL , whitespace))
{
if( strcmp( word ,"the") == 0 )
{
count++;
}
}
}
printf("%d\n",count);

return EXIT_SUCCESS;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐