How to count the number of words in English text through C language?

CSDN Q & A 2022-05-15 04:59:05 阅读数:568

The phenomenon and background of the problem

As the title . If I input an English material text and a key word text . All words in two texts do not include spaces and straddles between words , Letters are not case sensitive . The English material text is a normal English novel paragraph . The key word text is composed of only words , Words are separated by commas .
The program counts the total number of times the words in the key word text appear in the English data text , And sort the words according to the number of occurrences .
Output key words according to the number of occurrences from large to small . The output format doesn't matter . How to design this kind of small program code . I'm an English college student , learn by oneself C Language . Want to design a small program for high-speed review . But I have no idea .

Operation results and error reporting contents
My solution ideas and tried methods
What I want to achieve

Please try to use basic grammar , I am a beginner , Advanced grammar can't be understood very well

Take the answer :

Mainly the segmentation and comparison of strings .
(1) First extract the end word , Put it in an array ( If you've learned STL Containers , It can also be used. list perhaps vector Containers ), And use an array to record the number of key words .
(2) Read English data text ( It can be read line by line , It can also be read at one time , The treatment is similar to ), Take line by line reading as an example :
(a) Read a line of text , Deposit in char Array
(b) Traverse char Array , Use spaces , comma , spot , question mark , Exclamation mark split string , Extract all the words in this line .
(c) Take out one word at a time , Judge whether the word is in the key word array , If in , Just put the corresponding number of words +1
(d) Continue reading one line , continue a-c Steps for , Until the file is read .

There is a read file in the following connection , And count the number of words , On the basis of it, add the statistics of key words .

版权声明:本文为[CSDN Q & A]所创,转载请带上原文链接,感谢。