Zi 字媒體
2017-07-25T20:27:27+00:00
Linux C function() 參考手冊:strspn(返回字串中連續不含指定字串內容的位置)-很難用
資料來源:http://people.cs.nctu.edu.tw/~yslin/library/linuxc/main.htm線上執行:http://www.tutorialspoint.com/compile_c_online.phpcode2html:http://tohtml.com/
相關函數strcspn,strchr,strpbrk,strsep,strstr表頭文件#include定義函數size_t strspn (const char *s,const char * accept);函數說明strspn()從參數s 字符串的開頭計算連續的字符,而這些字符都完全是accept 所指字符串中的字符。簡單的說,若strspn()返回的數值為n,則代表字符串s 開頭連續有n 個字符都是屬於字符串accept內的字符。返回值返回字符串s開頭連續包含字符串accept內的字符數目。範例
#include <string.h>
#include <stdio.h>
int main()
{
char *str="Linux was first developed for 386/486-based PCs.";
char *t1="for";
char *t2="Linux was first";
char *t3="f";
printf("%d\n",strspn(str,t1));//一開始就不一樣,所以回傳0
printf("%d\n",strspn(str,t2));//到第16之後不同,所以回傳16
printf("%d\n",strspn(str,t3));//一開始就不一樣,所以回傳0
return 0;
}
寫了
5860316篇文章,獲得
23313次喜歡