I am trying to get a program working, and im half way there, I think. What the program must do is take input from the keyboard and then capitalize every first letter of every word. Here is my entire program so far...
#include <stdio.h>
#include <iostream>
using namespace std;
int main (int argc, char *argv[], char **env)
{
char c, lastc = ' ' ;
c = cin.get();
do {
cout.put(c);
c = cin.get();
if (lastc)
{
c = toupper(c);
}
} while ( !cin.eof());
return EXIT_SUCCESS;
}
The part where I am trying to do this is at:
if (lastc)
{
c = toupper(c);
}
Basically the approach I am taking is having the program to recognize when there is a space or ' ' and have it capitalize the first letter after that.
When executed now my program capitalizes the whole word. I have searched for a couple hours now on these forums and over the net and havent found any code that might help me out.
Is there a command in C++ that I could use to capitalize only the first letter and not the whole word?