Hi, I wrote this code first then was asked to modify it so that the program read the contents of the first file and change all the letters to lowercase except the first letter of each sentence, which should be made uppercase. The revised contents should be stored in the second file. How can i form a loop that can do this successfully?
You should add a variable to keep track of whether the code is in the middle of a sentence or not. Whenever you encounter a period, exclamation point, or question mark, set the variable to false (you are no longer in the sentence). If you encounter a letter while the variable is false (the first letter of a sentence), skip the ch2 = tolower(ch2) and set the variable to true. Otherwise, run ch2 = tolower(ch).
have a while loop that loops until the end of the file
use get() to capture one character and read it into a single temp char
use isspace() to loop until you receive a non-whitespace character
receive non-whitespace character and stop looping
use toupper() to capitalize it
loop until you receive a character that ends a sentence
for each of the characters, use tolower() to lower case them
receive a period, question mark, etc., stop looping
write every character you receive to the output file (after modifying it if applicable)
end of outer loop