/*
编写一个程序, 对标准输入进行扫描, 并对单词"the" 出现的次数进行计算. 进行比较时应区分大小写, 所以"THE", 和"The" 并不计算在内.
你可以认为各单词由一个或多个空格字符分割, 而且输入的行在长度上不会超过100 个字符.
计算结果应该写在标准输出上.
*/
typedef char bool;
#define true 1
#define false 0
#define MAX_SIZE 102
#define TAG_WORD "the"
bool Is_FrontPunct( char ch );
bool Is_BehindPunct( char ch );
#include <stdio.h>
#include <string.h>
int main( void )
{
/*
* buf: 存放用户输入的一行文本
* tagWord: 需要检测的目标单词
* tagWordLen: 目标单词长度
* tagWordCnt: 目标单词出现次数
* offset: 遍历buf 时的偏移量
* inputLen: 输入行字符串长度, 最后一位是换行符 '\n'
*/
char buf[MAX_SIZE];
char *const tagWord = TAG_WORD;
unsigned int tagWordLen;
unsigned int tagWordCnt;
unsigned int offset;
unsigned int inputLen;
tagWordLen = strlen( tagWord );
printf( "请输入一行字符串(长度不超过%d个字符), 程序将会统计输入字符串中单词%s出现的次数.\n", MAX_SIZE - 2, tagWord )<
C和指针_编程练习_第9章_第11题
最新推荐文章于 2024-07-25 15:19:39 发布