First of all, don’t take it too seriously. The address has been sent to me. The error has always changed.
Pure logic version is not confused ha ha ha
Subject Requirements:
- Read a character in a file
- Type the number of words in each paragraph
- Print and output according to paragraphs (insert behavior segment)
- Type the length of the longest word in each paragraph
Clarification required:
According to the method based on English word formation, the total stats of the word
- It will be formed as I am, Mr. Wang, Brat Time, short-term, No. 1 and other statistics as a word as a word
- Mix numbers with words like Rond2, Part1, B2c, etc.
- Stats like 150.5, 99%, 100, $0.1, etc.
- The single character must be based on specific requirements: +, – thought is a plus, minus, positive hyphen, etc.
- ……
Here the first three cases are considered
Demolition content -> integrated data
division |
---|
Drink with words |
Words are divided into letters |
Set the judgment to check if the character matches Synovi’s method |
Merge |
---|
Print the number of words in a paragraph, the total number of statistics |
// true copy
#include<stdio.h>
#include<stdlib.h>
int isPartOfWord( char ch, char *Pre){
int Cur_Flag = 1,
general = 0,
number = 0,
other = 0;
general = ( ('a'<=*Pre&&*Pre<='z'||'A'<=*Pre&&*Pre<='Z')
&& (ch =='\''|| ch =='-'|| ch == '\.') )
||( ('a'<=ch && ch<='z'||'A'<= ch&& ch<='Z')
&& (*Pre =='\''|| *Pre =='-'|| *Pre =='\.'))
|| ('a'<=ch&&ch<='z'||'A'<=ch&&ch<='Z');
number = ((*Pre=='\.') && ('0'<= ch&& ch<='9'))
|| (( ch=='\.') && ('0'<=*Pre&&*Pre<='9'))
|| ( '$'==*Pre &&('0'<= ch&& ch<='9'))
|| (( ch=='%') && ('0'<=*Pre&&*Pre<='9'))
|| ( '0'<=ch&&ch<='9');
Cur_Flag = ( general||number||other );
*Pre = ch;
return Cur_Flag;
}
int Count_words( char *string){
char PreLetter = 0;
int i = 0,
flag = 0,
count = 0;
while(!(('a'<=string[i]&&string[i]<='z'||'A'<=string[i]&&string[i]<='Z')
||( '0'<=string[i]&&string[i]<='9')) ) i++;
while(1){
if((string[i]!='\n')&&(string[i]!='\0')){
if (isPartOfWord(string[i],&PreLetter)) flag = 0;
else if(flag==0){
flag = 1;
count++ ;
}
++i;
}
else {
if(flag==0) {
++count;
++i;
}
break;
}
}
return count;
}
int functional( FILE *fl){
int len = 0,
i = 0,
max = 0,
n = 10000,
count_words_all = 0,
count_words_this_paragraph = 0;
char pre,
str[n];
memset(str,0,n);
while(fgets(str,n,fl)){
count_words_this_paragraph = Count_words(str);
count_words_all += count_words_this_paragraph;
printf("count_words_this_paragraph: \t%d\n\n%s\n",count_words_this_paragraph,str);
for(i = 0; i < n; i++ ){
if(isPartOfWord(str[i],&pre)&&str[i]!='\n') max = ++len>max ? len : max;
else len = 0;
}
printf("---max length :%d\t\n---------------------------------\n",max);
max = 0 ;
memset(str,0,n);
}
return count_words_all;
}
int main(){
FILE *fl = fopen( "D:\\Temp\\FileTest\\Words.txt", "r");
printf("\n\ncount_words_all:%d\n",functional(fl));
fclose(fl);
return 0;
}
work result
Error resolved:
- The legislative character directly accompanied by the change or termination of personality is not taken into account
- The first character. diving count
- The memory memory has not been initialized, causing a response error on memory that has no sense around the trace