Sunday 20 July 2014

How to Find a Character in String

Structure of the Problem Requirements 

String Contain the textual data and empty space. In this Problem we deal with String and 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 No.

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
Search a Character from String 






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