/*********************************************************************************************************************
Author:RainGiving
Date:2020-03-14
Description:一个统计单词个数的小程序
1.我们选定一个文本中不常用的字符作为输入的末尾标记
2.使用循环体+getchar()进行输入,通过检查换行字符统计行数
3.一个单词一定是一个非空白字符开始,读到一个空白字符时结束
4.用函数isspace()很方便地判断是否输入了空白字符,是空白字符isspace(c)为真;不是空白字符!isspace(c)为真
5.设置一个上一个单词prev,用来判定最后一行是不是完整行
6.下面说说识别单词的一种思路
i.程序读入一个单词的首字符时把一个标记(inword)设置为1,然后递增单词计数,只要inword是1,后续单词都不计为单词开始
ii.读到下一个空白字符,将inword设置为0,然后准备读取下一个单词
1. We select an unusual character in the text as the end of the input
2. Enter using the body of the loop +getchar() and count the number of lines by checking the newline characters
A word must start with a non-whitespace character and end with a whitespace character
4. The function isspace() is very convenient to determine whether a blank character is entered, and the blank character isspace(c) is true; Not white space! Isspace (c) is true
5. Set the previous word prev to determine if the last line is complete
6. Here is a way to recognize words
i. When the program reads in the first character of a word, it sets a mark (inword) to 1, and then increments the word count. As long as the inword is 1, subsequent words are not counted as the beginning of the word
ii. Read the next white space character, set inword to 0, and prepare
C语言统计单词数量程序 超详解
最新推荐文章于 2025-04-02 23:40:46 发布