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; }
0 comments:
Post a Comment