/* memchr */ #include <iostream> #include <cstring> #include <cstdio> using namespace std; int main() { char *pch; char str[]="Example string"; pch=(char*)memchr(str,'p',strlen(str)); if(pch!=NULL) cout<<"'p' found at position "<<pch-str+1<<" ./n"; else cout<<"'p' not found./n"; return 0; } /* strchr */ #include <iostream> #include <cstring> using namespace std; int main() { char str[]="This is a sample string"; char *pch; cout<<"Looking for the 's' character in /""<<str<<"/".../n"; pch=strchr(str,'s'); while(pch!=NULL) { cout<<"found at "<<pch-str+1<<endl; pch=strchr(pch+1,'s'); } return 0; } /* strcspn */ #include <iostream> #include <cstring> using namespace std; int main() { char str[]="fcba73"; char keys[]="1234567890"; int i; i=strcspn(str,keys); cout<<"The first number in str is at position "<<i+1<<"./n"; return 0; } /* strpbrk */ #include <iostream> #include <cstring> using namespace std; int main() { char str[]="This is a sample string"; char key[]="aeiou"; char *pch; cout<<"Vowel in '"<<str<<"':"; pch=strpbrk(str,key); while(pch!=NULL) { cout<<*pch<<" "; pch=strpbrk(pch+1,key); } cout<<endl; return 0; } /* strrchr */ #include <iostream> #include <cstring> using namespace std; int main() { char str[]="This is a sample string"; char *pch; pch=strrchr(str,'s'); cout<<"Last occurence of 's' found at "<<pch-str+1<<endl; return 0; } /* strspn */ #include <iostream> #include <cstring> using namespace std; int main() { int i; char strtext[]="129th"; char cset[]="1234567890"; i=strspn(strtext,cset); cout<<"The length of initial number is "<<i<<"./n"; return 0; } /* strstr */ #include <iostream> #include <cstring> using namespace std; int main() { char str[]="This is a simple string"; char *pch; pch=strstr(str,"simple"); strncpy(pch,"sample",6); cout<<str; return 0; } /* strtok */ #include <iostream> #include <cstring> using namespace std; int main() { char str[]="- This,a sample string."; char *pch; cout<<"Splitting string /""<<str<<"/" into tokens:/n"; pch=strtok(str," ,.-"); while(pch!=NULL) { cout<<pch<<endl; pch=strtok(NULL," ,.-"); } return 0; }