Wednesday 28 January 2015

Use ASCII values to count number of character in C++

Structure of the Problem Requirements 

This Program count number of characters in a string using ASCII values in C++ program. After getting string from user the program will display the table in which told how many times a characters occur . Note ASCII values has different code for upper and lower case and this program also manage it.

Source Code

#include <iostream>
using namespace std;
int main(int argc, char** argv) {
string sentence;
int count=0;
int a;
char c1;
cout<< "Enter a sentence with \".\" at End"<<endl;
getline(cin,sentence,'.') ;
for(int i=65;i<123;i++){
if(((i>64)&&(i<91))||((i>96)&&(i<123))){
if(i==97){
cout<<endl;
}
cout<< (char)i<< " = ";
for(int j=0;j<sentence.length();j++){
a=sentence[j];
if(a==i){
count=count+1;
}
}
cout<<count<< " | ";
}
count=0;
}
return 0;
}

Output of the Program

Use ASCII values to count number of character in C++

Share it Please
asad

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.

0 comments:

Post a Comment