Structure of the Problem Requirements
This Program will Capitalize the the words first letter in a string. For this we used C++ builtin functions isupper and isalpha. The user will enter a string and the program capitalized all the first characters of words with some logic which we define in condition .
Source Code
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;
int main()
{
const int Maxlength = 500;
char sentence[Maxlength];
char a = true;
cout << " Enter Your Story \n ";
cout<<endl;
cin.getline(sentence, Maxlength);
for (int i = 0; i < *(sentence); i++)
{
if (isalpha(sentence[i]) && a == true)
{
sentence[i] = toupper(sentence[i]);
a = false;
}
if (isspace (sentence[i+1]))
a = true;
}
cout<<endl;
cout <<" After Capitalizing the First Character of All Words now Your Story is \n \n ";
cout<<endl;
cout << sentence << endl;
return 0;
}
Output of the Program
0 comments:
Post a Comment