Ok, so I need a little bit of help with a program i'm writing. Let me give you the details.
The user is suppose to enter two sentences with all lower case letters and have the first letter of each sentence become capitalized.
Here is the code so far:
// Assignment 5: Sentence Capitalizer
#include <iostream>
#include <cctype>
using namespace std;
// Function prototype
void capital(char*);
int main()
{
char cstring[1024];
// Get a string from the user.
cout << "Enter at least two sentences, but do not use capital letters." << endl;
cin.getline(cstring, 1024);
// Capitalize the first word of each sentence.
capital(cstring);
// Display the resulting string.
cout << "Here are your sentences with beginning words capitalized:" << endl;
cout << cstring << endl << endl;
return 0;
}
void capital(char* cstring)
{
}
Now I'm need to write the definition of the capital function so that it takes the two sentences I entered and capitalized the first letter of each sentence. How do I go about doing this? I know a little about toupper(), but how do you make focus on only certain letters? Is it through a while or for loop?
The hints I was given were these: The capital function is not given the length of the string. It should therefore iterate until the null
terminator character ('\0') is found
and
capital should capitalize the first letter following any punctuation character other than a comma.
This implies that the function will need to maintain a
flag (e.g. lastWasPunctuation) that indicates when the last non-space character that was processed was a
punctuation character.Note that the first non-space letter in the string should be capitalized.
This case can be handled by careful initialization of the lastWasPunctuation flag.
I appreciate any advice given. Thank you.