I had to use a file to input a text with all capitol letters.
The pgm had to make all letters lowercase then change the first letter of each sentence into a capitol.
i read in the text using
string text
and changed the letters to lower case but now im having difficulty creating a loop to change the first letter of a sentence to a capitol.
This is what i did
text[0] = std::toupper(text[0]);
for (int x = 0; x <100; x ++){
loc[x] = text.find ('.');
text[loc[x]+2] = toupper(text[loc[x]+2]);
}
The first letter of the text gets capitalized and so does the first letter of the second sentence but thats all.
I would just take the whole sentence at a time and put it in a string called string sentence.
1 2
string sentence;
getline(fileName, sentence);
This will get the whole sentence (line) from the file and store it in string sentence.
Then, I would convert whole sentence to lower case and I wrote a little function for that.
// this function takes your sentence as parameter and return this sentence in lowercase
1 2 3 4 5 6 7 8 9 10 11 12 13
string lowerCase(string sentence)
{
for (int i=0; i<sentence.length(); i++)
{
sentence[i] = tolower(sentence[i]);
}
return sentence;
}
// Then Finally, I would convert the first letter to uppercase.
// sentence[0] = toupper(sentence[0]);
cout << sentence << endl;