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?
10 Respostas
0
Take 'h' instead of "h".
Edit:
Post your full code..
Are you added header file <cstring>?
0
Still error.. 😞
0
Yes..!
0
#include <iostream>
#include<cstring>
using namespace std;
int main()
{
char p1[25]={"hii"} ;
char p2[25]={"hello"};
cout<<strchr(p2,'h');
return 0;
}
0
strchr return the pointer or location if the charecter present. Otherwise it return null.
Do you want print charecter location? Or charecter?
0
Charcter..!
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;
}
0
Wow.. 👍
0
Thanks a lot..
0
M Rishi you're welcome..