Showing posts with label How Count Number of Character is a String in Cplusplus. Show all posts
Showing posts with label How Count Number of Character is a String in Cplusplus. Show all posts

Monday, 8 September 2014

Count Number of Character in String

Structure of the Problem Requirements 

In this problem we will learn how to count number of characters in C++ Programs. The program asked user to enter a string and then count the number of character include space and special characters. In this problem we used gets(str) functions which also count as a character . Here is the source code of this problem which help you in better understanding. 

Source Code 



#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
int main ()
{
char story [150];
int words =0;
cout<<" \t \t \t LEP \n \n \n  ";
cout<<" \t \t Enter Your Story  \n  ";
cout<<endl;
gets (story);
for(int i =0; story[i]!='\0';i++)
{
words++;
}
cout<<endl;
cout<<"Your Story Contain "<<words<<" Character"<<endl;
return 0;
}

Output of the Program

Count Number of Characters
Count Number of Characters in C++ Program