0

Can any one tell about strchr string in c++? And I need basic syntax.. Some example program!!

Char n1[25]={"hello"} ; cout<< strchr(n1, "h" ) ;..... I don't know what's wrong form this error.. Could any one find it?

23rd Jul 2020, 2:44 PM
M Rishi
10 Antworten
0
Take 'h' instead of "h". Edit: Post your full code.. Are you added header file <cstring>?
23rd Jul 2020, 3:51 PM
Jayakrishna 🇮🇳
0
Still error.. 😞
23rd Jul 2020, 4:32 PM
M Rishi
0
Yes..!
23rd Jul 2020, 5:11 PM
M Rishi
0
#include <iostream> #include<cstring> using namespace std; int main() { char p1[25]={"hii"} ; char p2[25]={"hello"}; cout<<strchr(p2,'h'); return 0; }
23rd Jul 2020, 5:11 PM
M Rishi
0
strchr return the pointer or location if the charecter present. Otherwise it return null. Do you want print charecter location? Or charecter?
23rd Jul 2020, 5:42 PM
Jayakrishna 🇮🇳
0
Charcter..!
23rd Jul 2020, 5:44 PM
M Rishi
0
#include <iostream> #include<cstring> using namespace std; int main() { //char p1[25]={"hii"} ; char p2[25]={"hello"}; if(strchr(p2,'h')) //Return null if no charecter h. { cout<<"charecter :"<< *strchr(p2,'h') <<endl; //derefferencing at returned location cout<<"at position : "<< strchr(p2,'h') - p2 ; //getting locstion } else cout<<"no charecter h in p2"; return 0; }
23rd Jul 2020, 5:47 PM
Jayakrishna 🇮🇳
0
Wow.. 👍
23rd Jul 2020, 5:49 PM
M Rishi
0
Thanks a lot..
23rd Jul 2020, 5:50 PM
M Rishi
0
M Rishi you're welcome..
23rd Jul 2020, 5:50 PM
Jayakrishna 🇮🇳