C 語言標準函數庫分類導覽 - string.h strrchr()

string.h 的函數 strrchr() ,需要一個字串及一個字元當作參數,回傳在字串中作為參數的字元最後一次出現位置的指標。



以下程式印出在字串 s 中含有空格的最後的子字串
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
#include <string.h>
 
int main(void)
{
    char s[] = "Necessity is the mother of invention.";
    char *test;
     
    test = strrchr(s, ' ');
    printf("%s\n", test);
     
    return 0;   
}
 
/* 《程式語言教學誌》的範例程式
    檔名:cstrrchr.c
    功能:示範 string.h 中函數 strrchr() 的使用
    作者:張凱慶
    時間:西元2010年6月 */


編譯後執行,結果如下



您可以繼續參考


沒有留言: