Hi. I need to write a C program to print a passage of text (from a filein.txt) with the following conditions and I need a lot of help.
1) right justified. (what's the diff between justified and right-justified anyway?)
2) extra spaces spread evenly between words (in relation to the above condition)
3) n characters per line, including the spaces (the variable n is user-prompted)
4) no broken words
5) no puntuation at the start of each line
I really hope you guys will help! I have no idea how to even start this and the deadline is looming so I'm all freaked out. Thanks very much in advance!
C programming help: how to right-justify text?
Starting with the first, try the first URL below to explain that. You'll have to read a ways, though.
Second, you'll need to write a function to count words and spaces and distribute them with another function called the necessary number of times to insert a space. Doing it this way seems inefficient, but it is easier to keep straight. You can use a variable to hold the result and send it through this function that many times as needed in a loop.
Third, you'll need to prompt for the user to enter this first, then mesh it as a variable into the function used to count and distribute the words as a maximum value. Any word that breaks before a trailing space must be held over for the next line and padding added, which takes care of number 4.
Number 5 will usually take care of itself if you break a "word" on a space, but you should probably write a redundant check function in case a typo like this occurs . You could elect to remove the errant space if you wanted to at that point.
I hope this will get you started, deep breath and take one step through until it works then add the next. You'll be done in no time. Or real time anyway! Pivy.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment