20180912-3 word frequency statistics

This job requires see [https://edu.cnblogs.com/campus/nenu/2019fall/homework/6583]

 

Word frequency statistics SPEC 20180918

Five in the bedroom of his bragging familiar with the "Robinson Crusoe" in front of the girls bragging love "Wuthering Heights," "Jane Eyre" and "Gone with the Wind", read through before you say, "War and Peace." However, he has not had four. You guys talk privately, vocabulary this masterpiece of how these may be less than four, we heard that you learn "building law", unanimously elected you write a program called wf, vocabulary English works and gives statistics the number of times each word appears, ready to fight for the Five face.

We hope to achieve the following effects. The following is purely fabricated digital effects.

Function 1  small file input. To demonstrate the program run, and not the result of real persecution Five, ask him personally key
pad to enter commands at the console.

Ideological function 1: Using three arrays for receiving word memory the words and word count. The number of letters is traversed. Each recording a word to determine whether the word has appeared, if not appeared on the record of the word, if the word had appeared, the number of words plus one.

 gets(str2);
    t=strlen(str2)+1;
    while(j<t)  
    {
        for(;str2[j]==32;j++);

        while(k<N&&str2[j]!=32) 
                str1[i][k++]=str2[j++]; 
        str1[i][k]='\0';
        strC[i]=1;  
        for(x=0;x<i;x++)  
            if(strncmp(str1[i],str1[x],N)==0) 
            {
                strC[x]++; 
                i--;      
                break;
            }      
            i++;  
            k=0;
    }
    printf("total %d\n\n",i);   
    int n=0,max,temp;
    while(n<i){
        max=0;
        for(int t=0;t<i;t++){
            if((strC[t]>max)&&(strC[t]!=0)){
                temp=t;
                max=strC[t];
            }
        }
        printf("%s,%d\n",str1[temp],strC[temp]);
        strC[temp]=0;
        n++;
    }

To assess vocabulary Five instead of reading amount, the same total number of unique words in a count, appeared 2
times very counts 1 times.

Because the used console and command line, you already know, the above ">" called the command prompt, it is part of the operating system, rather than part of your program.

When this feature is to complete your experience +10.

 

Note: Due to time constraints, the file is too large to homework and can not deal with this problem, so the files were changed

Function 2  supports command line input English works of the file name, Five personally entry.

Thought 2 function: This function module used in a lot of c language syntax file processing, such as setting the read file path buffer, reading a file using a file, the file size of the buffer allocation, but also to close the file and other operations. The number of times the word appears in many processes and functions 1 and achieve similar functionality.

char *pchBuf = NULL;
    FILE *fp;
    int count=0;
    fp=fopen("word_count_demo.txt","r");
    fseek(fp,0,SEEK_END);
    int nlen=ftell(fp);
    rewind(fp);
    pchBuf = (char*) malloc(sizeof(char)*nlen+1);
    nlen = fread(pchBuf, sizeof(char), nlen, fp);
    pchBuf[nlen] = '\0';
    t=strlen(pchBuf)+1;

3 features  support for command line storage directory with the name of the English works of the document, the bulk statistics.
> the dir Folder
gone_with_the_wand
runbinson
janelove
> WF Folder
gone_with_the_wand
Total 1234567 words
The 5023
A 4783
Love 4572
Fire 4322
RUN 3822
Cheat 3023
Girls 2783
Girl 2572
Slave 1322
Buy 822
----
runbinson
Total 1234567 words

Function of thinking 3: innovations of this module, the path of the file (this is a relative path) as a variable is passed to the fopen, functions and other parts 2, 3, and there is an overlap function.

while(gets(path)){
        fp=fopen(path,"r");
        fseek(fp,0,SEEK_END);
        int nlen=ftell(fp);
        rewind(fp);
        pchBuf = (char*) malloc(sizeof(char)*nlen+1);
        nlen = fread(pchBuf, sizeof(char), nlen, fp);
        pchBuf[nlen] = '\0';
        printf("%s\n", pchBuf); 
        t=strlen(pchBuf)+1;
                ...
}

 

Function 4: thinking for a long time or not

to sum up:

    1. To achieve the function is more complex, relatively large, so it takes a long time.

    2. c language to read the file and other operations are not familiar with, so the homework at the same time, also need to review previous knowledge.

    3. Some features do not have enough time to implement and improve.

Guess you like

Origin www.cnblogs.com/samndbk/p/11536789.html