-
HW help
I really need some help with this hw assignment. I'm not sure how to write these fuctions...
Write a program to process text files. The program should read a text file and output the data in the file as is. The program should also output the number of words, number of lines, and the number of paragraphs.
You must write and use the following functions.
a) initialize: This function initializes all the variables of the function main
b) processBlank: This function reads and writes blanks. Whenever it hits a nonblank(except whitespace characters), it increments the number of words in a line. The number of words in a line is set back to zero in the function updateCount. The function exits after processing the blanks.
c) copyText: This function reads and writes the nonblank characters. Whenever it hits a blank, it exits.
d) updateCount: This function takes place at the end of each line. It updates the total word count, increments the number of lines, and sets the number of words on a line back to zero. If there are no words in a line, it increments the number of paragraphs. One blank line(between paragraphs) is used to distinguish paragraphs and should not be counted with the number of lines.
e) printTotal: This function ouputs the number of words, number of lines, and number of paragraphs.
Your program should read data from a file and send output to a file. Do not use any global variables. Use the appropriate parameters to pass values in and out of the functions described above.
Any help would be greatly appreciated. Thanks.
-
Ffirst write an empty program with only a main function. Then make sure it compiles. Then, one at a time, add each of the functions mentioned above with void return value and no parameters, compiling each one to make sure there are no typos. Then, for initialize, add the appropriate parameters but don't do anything with them. Add a call to this function from main passing the appropriate variables. Make sure it compiles. Then slowly implement initialize.
When you are done implementing initialize, move on to the next one. Maybe before getting in too deep, write out on paper what kind of variables you will need, and what variables each function will need. Since there are no global variables, you will create all your variables in main and pass them to each function as needed. Having the flow written on paper will help you as you do each step.
-
I'm still confused on how to write functions b) c) and d).
-
Then show what you've tried for one of them (remember do one at a time and make sure it is working) and maybe somebody will be able to help you.
-
Yeah, man. You're asking us to do your homework for you.
Try it yourself, see if you can get it to work. If you can't, show us the code you wrote and we'll help you from there.