# include & lt; stdio.h>
#include
#include
#include
#include
Int main () {
The FILE * text;
Const int MAXSIZE=1000;//maximum length of string
Int I=0, num=0, space=0, symbol=0, number=0, letter=0, word=0, line=0, English=0;
Char STR [MAXSIZE];
Text=fopen (" test. TXT ", "r");
If (NULL==text)
Printf (" erro!" );
The else {
while (! The feof (text)) {
The fgets (STR, MAXSIZE, text);
}
Printf (" % s ", STR);
I=0;
If (STR [0]!='\ 0')
Line++;//determine the string is not empty
While (STR [I]!='\ 0') {
If (int (STR [I])==32)
Space++;//space
Else if ((int (STR) [I] & gt; 32 & amp; & Int (STR [I]) & lt; 48) | | (int (STR) [I] & gt; 57 & amp; & Int (STR [I]) & lt; 65) | |
(int (STR) [I] & gt; 91 & amp; & Int (STR [I]) & lt; 97) | | (int (STR) [I] & gt; 122 & amp; & Int (STR [I]) & lt; 128))
Symbol++;//punctuation
Else if ((int (STR) [I] & gt; 47 & amp; & Int (STR [I]) & lt; 58))
Number++;//number
Else if ((int (STR) [I] & gt; 64 & amp; & Int (STR [I]) & lt; 91) | | (int (STR) [I] & gt; 96 & amp; & Int (STR [I]) & lt; 123))
Letter++;//English
Else if (int (STR) [I] <0)
Word++;//Chinese
If ((I + 1 - num)/120 & gt; 0 {
Num +=120;
Line++;//the number of rows
}
If (I & gt; 0)
If (((int (STR [I - 1]) & gt; 64 & amp; & Int (STR [I - 1]) & lt; 91) | | (int (STR) [I - 1] & gt; 96 & amp; & Int (STR [I - 1]) & lt; 123)) & amp; &
((STR [I]==' ') | | (int (STR [I]) & gt; 32 & amp; & Int (STR [I]) & lt; 48) | | (int (STR) [I] & gt; 57 & amp; & Int (STR [I]) & lt; 65) | |
(int (STR) [I] & gt; 91 & amp; & Int (STR [I]) & lt; 97) | | (int (STR) [I] & gt; 122 & amp; & Int (STR [I]) & lt; 128))) {
English++;//words
}
i++;
}
Word/=2;
The fclose (text);
Printf (" \ n space=% d \ n \ n punctuation=% d digital=% d=% d \ n \ n letters in Chinese=% d \ n rows==% d % d \ n word "
, space, symbol, number, letter, word, line, English);
}
return 0;
}
Program is the function of the statistical data of text space punctuation alphanumeric number of lines in Chinese word paragraph number, the question now is when I read the data, to return to, paragraph will only read the data from the last paragraph, but in front of all the data will be abandoned,


Document data as follows:
you ready? Statistics basic information and other basic operations, a text file in a text file in advance for the Chinese, English, as well as a variety of punctuation, try to write programs statistics of characters (including Spaces), the total number of Spaces, letters, digital number, number of punctuation marks, number of characters (including Chinese punctuation), number of words, the number of lines and paragraphs, 0123456789
Are you ready? Statistics basic information and other basic operations, a text file in a text file in advance for Chinese, 0123456789
To solve the
CodePudding user response:
Has been solved, after each reading to enter the fgets read will all come to an end, the reasons for this situation is then read data will be in front of the data to the coversCodePudding user response:
Program the fgets in a while loop of the building Lord, in front of nature at the back of the cover, into every time after the fgets to judge Spaces, characters, Numbers, and so on can be ~Advice to judge the fgets return values, in addition, pay attention to the fgets will add carriage return to the ~ in the cache
CodePudding user response: