Wednesday, 4 February 2015

Capitalizing Words First Character in C++

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 ";
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 <<" After Capitalizing the First Character of All Words now Your Story is \n \n ";
cout << sentence << endl;

return 0;

Output of the Program

Capitalizing Words First Character in C++

Share it Please

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.


Post a Comment