This program access the file and changes the all uppercase sentenced to lower case. I used the tolower function.
The trick how do I make the first letter of each sentence uppercase. I know I can use toupper but how do I tell the program where to use it. The sentences will change so they are not fixed in length.
// This program takes uppercase sentences from one file and makes them lowercase
#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
usingnamespace std;
int main()
{
string fileName; // Holds filename
char ch; // Holds a character
ifstream inFile; // Input file
// Open file for output.
ofstream outFile("challengeOut.txt");
// Get the input file.
cout << "Enter a file name: ";
cin >> fileName;
// Open file for input.
inFile.open(fileName.c_str());
// If input file opened successfully, continue.
if (inFile)
{
// Read char from file 1.
inFile.get(ch);
// If last read operation was successful.
while (inFile)
{
//Write lowercase char to file 2.
outFile.put(tolower(ch));
// Read another char from file 1.
inFile.get(ch);
}
// Close files.
inFile.close();
outFile.close();
cout << "File conversion done.\n";
}
else
cout << "Cannot open " << fileName << endl;
system("pause");
return 0;
}
That's the problem I can't figure out how to tell the computer what to do AFTER the new line. I know I can tell it if (ch = '\n') but I don't know how to tell it to manipulate the next character. I also don't know how to get the very first letter capitalized. I have not worked with strings yet, but it looks like an array. Is it assigned the same way?
I don't know if that will work or not the sentences are in a file and they have to be changed from uppercase to lowercase with the first letter capitalized. So it's reading one letter at a time. I really just need to know how to signify I only want the first letter of each sentence then I can use toupper.