最近在 複習C/C++部分知識,在準備着 招聘。。。。。
char * strchr(char * str, int ch) :功能就是找出在字符串str中第一次出項字符ch的位置,找到就返回該字符位置的指針,如果找不到就返回空指針(就是 null)。
代碼實現:
char str[20]="Hello world";
char c = 'o';
printf("%s\n",strchr(str,c));
輸出結果:o world
char * strstr(char * str1,char * str2);功能就是找出在字符串str1中第一次出項字符串str2的位置(也就是說字符串sr1中要包含有字符串str2),如果找不到就返回空指針(就是 null)。
代碼實例:
char str[20]="Hello world";
char c[4] = "el";
printf("%s\n",strstr(str,c));
輸出結果:ello world