Word Frequency statistics (second week)

Source: Internet
Author: User

New feature requirements:

1. small file input. Enter the command under Console.

2. Support command line input file name of English works.

Some core code:

Structure definition:

Defines a struct to hold the number of read words and their statistics.

struct addup{    char word[];    int count;} R;     

Read text:

       Char temp[]; R fin[10000]={"",0Char file[]; Fflush (stdin); Gets (file); Fp=freopen (file,"R", stdin);            

Word Matching:

For each word read, compare the number of previously accessed words in the struct, and if they are the same, update the array if they are different.

while (!feof (FP)) {fscanf (FP), "%s" ,TEMP); Q=strlen (temp); N++for (I=0;i<n;++i ") Span style= "color: #0000ff;" >if (strcmp (fin[i].word,temp) ==0) {fin[i].count++< Span style= "color: #000000;" >; N--breakif (I>=n) {strcpy (fin[n- 1].word,temp); Fin[n-1].count++      

Punctuation Determination:

The read string is measured in characters and removed.

for (I=0;i<q;i++if (Temp[i]== , ' | | Temp[i]== ' . "| | Temp[i]== ' ? "| | Temp[i]== ' ! "| | Temp[i]== '   ) Temp[i]= ' \0 ;}  

Bubble Sort:

For (i=0;i<n;i++) for          (j=0;j<n-i;j++if (fin[j].count<fin[j+1].count) {ls [0]=fin[j+1]; fin[j+1]=fin[j]; fin[j]=ls[0      

Output Result:

  if (m!=1)
printf ("Total%d words\n\n", m);
else printf ("Total 1 word\n\n");
for (i=0;i<n;i++) {printf ("%s: ", Fin[i].word); s=0; for (j=0;j<fin[i].count;++j) s++; printf ("%d times ", s); printf ("\ n");}

Operation Result:

Function 1:

Function 2:

PSP Table

Analysis requirements, design 15:20 15:30 0 10
Coding Realize 15:30 16:20 0 50
Document Program Description, essay 23:40 0:05 0 25
Discuss Program improvements -- -- --


Planning 12%
Development 59%
Reporting 29%

Word Frequency statistics (second week)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.