The deadline for this lab is Tuesday 15 April 2008, 17:45:59 hours. Strictly no submissions will be accepted after the deadline.
English has many punctuation characters. Which punctuation characters occur most often?
Your task is to write a simple program that reads in a text file, counts the frequency of each punctuation character, and display the results in a sorted order on the screen.
Punctuation characters are defined as any non-control character that is not a letter, digit, or whitespace.
http://www.rpbridge.net/8t69.htm
Board 1
North Deals S 10 9 3
None Vul H 9 7 5 4
D K 10 5
C 9 8 6
S Q S J 7 6 5 4
H A K Q J 10 3 H -
D 8 7 6 4 D A Q J 9 3
C 10 2 C A K 5
S A K 8 2
H 8 6 2
D 2
C Q J 7 4 3
Off to a red-hot start! East-West can make a slam in either red suit,
but it's hardly biddable. A common auction should be:
West North East South
Pass 1S Pass
2H Pass 3D Pass
4H All Pass
Some Souths may scrounge a 2C overcall, which should not change the
East-West bidding. West might sense a slam after East's 3D bid, but
the four-card fit is less appealing without an honor. The key to slam is
East having almost all his points outside of spades -- hard to
visualize, unless the Bridge Laws allowed an opening of "one no
spades."
In hearts, 12 tricks are easily made by taking two diamond finesses.
After a club lead, it is tempting to try for all 13: Ruff the third
club, draw trumps, finesse diamonds once and hope they split. Oops; the
price of greed is then only 11 tricks. Been there; done that.
In diamonds, the same 12 tricks are available with careful play (ruff
two black cards, win three hearts, finesse trumps twice) but it is
doubtful many will play there. Even if West stretches to slam, it would
be quite a position to choose diamonds over hearts at matchpoints.
We will test your program with other text files.
$ gcc -Wall punct.c -o punct $ ./punct text1.txt . 13 , 12 - 7 / 3 : 3 " 2 ' 2 ; 2 ! 1 ( 1 ) 1 $
Notice that the output shows each punctuation character followed by the number of times it occurred in the text file. Punctuation characters that do not occur at all are not shown. The list is sorted in descending order of frequency. If one or more punctuation characters have the same frequency count, display the punctuation character with the lowest ASCII value first. You may use any sorting algorithm you wish. Hint: Maintain two arrays, one containing the punctuation characters, and the other containing the frequency count of each punctuation character.
You may assume that there are at the most 40 different punctuation characters.
You may assume that each line in the text file contains at the most 80 characters (excluding the newline characters).
You may assume that the text file always exists, and is always supplied as an argument on the command line. The name of the text file is obtained from this command line argument.
Remember to submit your program frequently using the submit punct.c command, and check your submission using the check command.
All the best!