Capitalizing Words First Character in C++

This Program will Capitalize the words first letter in a string. For this we used C++ builtin functions isupper and isalpha. 

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

Capitalizing Words First Character in C++

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment