Here is the problem from my Programming class:
Write a program that asks the user for two file names. The first file will be opened for input and the second file will be opened for output. (it will be assumed that the first file contains sentences that end with a period.) The program will 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.
I have figured out how to get all lower case letters in the file but cannot figure out how to make the first letter in every sentence uppercase. Thanks for any help you can give! Sorry if I didn't post this correctly, this is my first time.
#include <iostream>
#include <fstream>
#include <cctype> // Needed for tolower function.
using namespace std;
int main()
{
const int SIZE = 81; // Constant size of filenames
// Arrays for file names
char fileName1[SIZE];
char fileName2[SIZE];
char ch; // Holds character
ifstream inFile; // Input file stream object
fstream outFile; // Output file stream object
// Get FIRST file from user
cout << "Please enter the first file (sentences.txt).\n";
cin >> fileName1;
// Open file for input
inFile.open (fileName1);
// Test file for errors.
if (!inFile)
{
cout << "The file " << fileName1
<< " could not be opened.";
exit(0);
}
// Get SECOND file(user created) from user
cout << "Please enter a new file name to save the conversion(ie: [filename].txt).\n";
cin >> fileName2;
// Open and create fileName2 for output
outFile.open (fileName2, ios::out);
// Process files
inFile.get(ch);
while(!inFile.eof())
{
outFile.put(tolower(ch));
inFile.get(ch);
}
// Close files
inFile.close();
outFile.close();
// Let user know conversion is finished
cout << "File conversion is complete.\n";
return 0;
}