
C 速查手冊
11.3.12 strstr()
string.h 的函數 (function) strstr() ,需要兩個字串 (string) 參數 (parameter) ,回傳在第二個參數字串在第一個參數字串首次出現位置的指標 (pointer) 。
以下程式印出在字串 s 中含有字串 t 最初的子字串
#include <stdio.h>
#include <string.h>
int main(void)
{
    char s[] = "Self-trust is the first secret of success.";
    char t[] = "secret";
    char *test;
    
    test = strstr(s, t);
    printf("%s\n", test);
    
    return 0;    
}
/* 《程式語言教學誌》的範例程式
    http://kaiching.org/
    檔名:cstrstr.c
    功能:示範 string.h 中函數 strstr() 的使用
    作者:張凱慶 */
        
        編譯後執行,結果如下
| $ gcc cstrstr.c | 
| $ a.out | 
| secret of success. | 
| $ | 
