關於c語言的分解字串函式

2021-10-10 23:22:19 字數 462 閱讀 9856

分享乙個可以分解字串的函式strtok函式

1.作用 分解字串

2.宣告 char *strtok(char *str, const char *delim)

3.引數 1.str – 要被分解成一組小字串的字串。2.delim – 包含分隔符的 c 字串。

4.返回值該函式返回被分解的第乙個子字串,如果沒有可檢索的字串,則返回乙個空指標。

5.例項

#include

#include

int main (

)return(0

);}

6.輸出

this is

www.runoob.com

website

7.注意

strtok會修改str的值,要注意儲存原值如果要用的話。如果想要分割多種字元,可以使用陣列。如arr[10] = 。

分解字串

按要求分解字串,輸入兩個數m,n m代表輸入的m串字串,n代表輸出的每串字串的位數,不夠補0。例如 輸入2,8,abc 123456789 則輸出為 abc00000 12345678 90000000 分析思路 1.獲得字串的長度length後,判斷與 要輸出位數n 的大小,大於n的話,直接 pr...

strtok s分解字串

char strtok s char str,要分解的字串 const char delimiters,分隔符 char context 後續待分解字串 wcstok s是strtok s的寬字元版本 wchar t wcstok s wchar t str,const wchar t delimi...

STL中分解字串函式strtok

char strtok char s,const char delim 分解字串為一組字串。s為要分解的字串,delim為分隔符字串。strtok 用來將字串分割成乙個個片段。引數s指向欲分割的字串,引數delim則為分割字串,當strtok 在引數s的字串中發現到引數delim的分割字元時則會將該...