Program in C++ to find a given character in given string
#include<iostream> #include<string.h> #include<conio.h> using namespace std; int StrFind(char *str,char f) { int i,flag=1; for(i=0;str[i]!='\0';i++) { if(str[i]==f) { flag=0; return 0; break; } } if(flag==1) return 1; } int main() { char str1[100]; char ch; cout<<"Enter string :-"; cin.getline(str1,99); cout<<"Enter a character you wnat to search:-"; cin>>ch; int r=StrFind(str1,ch); if(r==0) cout<<ch<<" is present in given string."; else cout<<ch<<" is not present in given string."; return 0; }
Output:-
0 Comments