How to Find a Character in String

String Contain the textual data and empty space. In this Problem we deal with String to find a Character in String given by user. User will enter a Sentence in Command Prompt and after this Program will asked user to enter the alphabet that want to search . If that Character exist is String program will display message " exist" else Not exist.

Source Code 


#include<iostream>
#include<conio.h>
#include<stdio.h>
using namespace std;
int main()
{
 char str[30];
 int i;
 char ch;
 bool p=true;
 cout<<"\n *************** SEARCH CHARACHTER IN STRING ************** \n\n\n";
 cout<<"\n Enter String : ";
 gets(str);
 cout<<"\n\n Enter Character You Want To Search= ";
 cin>>ch;
 
 for(i=0;i<=strlen(str);i++)
 {
 
  if(str[i]==ch)
  {
   p=false;
   break;
  }
 }
 
 if(p==true)
 {
  cout<<"\n\n Character Not Present In String \n\n";
 }
 else
 {
  cout<<"\n\n Character Present In String";
 }

return 0;
}

Output of the Program


C++ String Searching

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