Question
my (count.c program) is working. When the program prompt Enter file name: I enter jabberwocky.txt. This jabberwocky.txt is inside the folder of my code. When
my (count.c program) is working. When the program prompt "Enter file name:" I enter jabberwocky.txt. This jabberwocky.txt is inside the folder of my code. When I run the program, the program prints out like this " jabberwocky.txt has 1043 characters"
jabberwocky.txt
'Twas brillig, and the slithy toves Did gyre and gimble in the wabe: All mimsy were the borogoves, And the mome raths outgrabe.
"Beware the Jabberwock, my son! The jaws that bite, the claws that catch! Beware the Jubjub bird, and shun The frumious Bandersnatch!"
He took his vorpal sword in hand: Long time the manxome foe he sought- So rested he by the Tumtum tree, And stood awhile in thought.
And, as in uffish thought he stood, The Jabberwock, with eyes of flame, Came wiffling through the tulgey wood, And burbled as it came!
One, two! One, two! And through and through The vorpal blade went snicker-snack! He left it dead, and with its head He went galumphing back.
"And hast thou slain the Jabberwock? Come to my arms, my beamish boy!
Need to do:
1) Word identifies 977 characters including spaces. Your count.c believes there are 1043. Make the corrections necessary to your code to count only the visible characters and spaces!
2) Count and print out the total number of characters without spaces! (The ctype.h will come in handy.)
3) Figure out how to count the lines and then display the count at the end. Notice in Word, that a line return at the end of the line does not add a line to the lines count. Notice that a new, blank file does not count any lines. (HINT: Count the lines by looking for a line return and then use an if statement with compound conditions at the end to decide if you should count one more line. With the approach, you will need to store the previous value of ch on each loop iteration.)
4) Figure out how to count words. Words are delineated by spaces or new lines. (We will not worry about hyphenated words at the end of a line!) You will need to set up a 'flag'. Flags often contain T/F and using 1/0 for values works perfectly. Use a flag to mark whether or not you have started looking at a word. Change the flag to 0 once a space or new line is encountered and increase the word count.
Here is some pseudocode...
declare begWord and initialize to 0 if ch is not a space, then set begWord to 1 if begWord is 1 AND the current ch is a white space character.... increase the word count reset begWord to 0
#includeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started