CODE
#include <fstream>
#include <iostream>
#include <cctype>
using namespace std;
int main()
{
//Variables
fstream TextFile;
const int intSIZE = 180;
int intCharLength = 0;
char charInputName[intSIZE];
char charName[intSIZE];
//Open the file
TextFile.open("ALLCAPS.txt", ios::in);
if (!TextFile)
{
cout << "ERROR: Unable to open file./n";
return 0;
}
//Program title
cout << "\t\t\t***Chapter 12: Sentence Capitalizer***\n\n";
//Read the text
TextFile.getline(charInputName, intSIZE, '/n');
//convert the text into lowercase
while (charInputName[intCharLength]<= strlen(charInputName))
{
charName[intCharLength] = tolower(charInputName[intCharLength]);
intCharLength++;
}
intCharLength = 0;
[b]//format the text into proper case
while (charInputName[intCharLength]<= strlen(charInputName))
{
if (charName[intCharLength] == '\n')
{
charName[intCharLength] = toupper(charName[intCharLength]);
}
intCharLength++;
} [/b]
//display the text
for (int intCount = 0; intCount <= strlen(charInputName); intCount++)
{
cout << charName[intCount];
}
cout << endl;
TextFile.close();
system ("PAUSE");
}
I'm trying to read 6 sentences from a file that are all in upper case and convert it into proper case and output that into a file. The code in question is bolded above.
Example:
Input File:
JACK WENT UP THE HILL.
HE FOUND JILL IN THE WELL.
HE LAUGHED AND LEFT JILL.
JILL CRIED ALL NIGHT.
JACK CAME BACK AND RESCUED JILL.
JACK AND JILL ARE NOW MARRIED.
Output File:
Jack went up the hill.
He found jill in the well.
He laughed and left jill.
Jill cried all night.
Jack came back and rescued jill.
Jack and jill are now married.
The only output i'm able to get is the 6 sentences, but they're all lower case. Thanks!
This post has been edited by wr3ckin_cr3w: 2 Jul, 2009 - 08:19 PM