C語言字串操作函式

2021-06-21 05:55:20 字數 4854 閱讀 1956

1.函式名: stpcpy 

功  能: 拷貝乙個字串到另乙個 

用  法: char *stpcpy(char *destin, char *source); 

程式例:

#include

#include

int main(void) 

2.函式名: strcat 

功  能: 字串拼接函式 

用  法: char *strcat(char *destin, char *source); 

程式例:

#include

#include

int main(void) 

3.函式名: strchr 

功  能: 在乙個串中查詢給定字元的第乙個匹配之處\ 

用  法: char *strchr(char *str, char c); 

程式例:

#include

#include

int main(void) 

4.函式名: strcmp 

功  能: 串比較 

用  法: int strcmp(char *str1, char *str2); 

看asic碼,str1>str2,返回值 > 0;兩串相等,返回0

程式例:

#include

#include

int main(void) 

5.函式名: strncmpi 

功  能: 將乙個串中的一部分與另乙個串比較, 不管大小寫 

用  法: int strncmpi(char *str1, char *str2, unsigned maxlen); 

程式例:

#include

#include

int main(void) 

6.函式名: strcpy 

功  能: 串拷貝 

用  法: char *strcpy(char *str1, char *str2); 

程式例:

#include

#include

int main(void) 

7.函式名: strcspn 

功  能: 在串中查詢第乙個給定字符集內容的段 

用  法: int strcspn(char *str1, char *str2); 

程式例:

#include

#include

#include

int main(void) 

8.函式名: strdup 

功  能: 將串拷貝到新建的位置處 

用  法: char *strdup(char *str); 

程式例:

#include

#include

#include

int main(void) 

9.函式名: stricmp 

功  能: 以大小寫不敏感方式比較兩個串 

用  法: int stricmp(char *str1, char *str2); 

程式例:

#include

#include

int main(void) 

10.函式名: strerror 

功  能: 返回指向錯誤資訊字串的指標 

用  法: char *strerror(int errnum); 

程式例:

#include

#include

int main(void) 

11.函式名: strcmpi 

功  能: 將乙個串與另乙個比較, 不管大小寫 

用  法: int strcmpi(char *str1, char *str2); 

程式例:

#include

#include

int main(void) 

12.函式名: strncmp 

功  能: 串比較 

用  法: int strncmp(char *str1, char *str2, int maxlen); 

程式例:

#include

#include

int  main(void)

13.函式名: strncmpi 

功  能: 把串中的一部分與另一串中的一部分比較, 不管大小寫 

用  法: int strncmpi(char *str1, char *str2); 

程式例:

#include

#include

int main(void) 

14.函式名: strncpy 

功  能: 串拷貝 

用  法: char *strncpy(char *destin, char *source, int maxlen); 

程式例:

#include

#include

int main(void) 

15.函式名: strnicmp 

功  能: 不注重大小寫地比較兩個串 

用  法: int strnicmp(char *str1, char *str2, unsigned maxlen); 

程式例:

#include

#include

int main(void) 

16.函式名: strnset 

功  能: 將乙個串中的所有字元都設為指定字元 

用  法: char *strnset(char *str, char ch, unsigned n); 

程式例:

#include

#include

int main(void) 

17.函式名: strpbrk 

功  能: 在串中查詢給定字符集中的字元 

用  法: char *strpbrk(char *str1, char *str2); 

程式例:

#include

#include

int main(void) 

18.函式名: strrchr 

功  能: 在串中查詢指定字元的最後乙個出現 

用  法: char *strrchr(char *str, char c); 

程式例:

#include

#include

int main(void) 

19.函式名: strrev 

功  能: 串倒轉 

用  法: char *strrev(char *str); 

程式例:

#include

#include

int main(void) 

20.函式名: strset 

功  能: 將乙個串中的所有字元都設為指定字元 

用  法: char *strset(char *str, char c); 

程式例:

#include

#include

int main(void) 

21.函式名: strspn 

功  能: 在串中查詢指定字符集的子集的第一次出現 

用  法: int strspn(char *str1, char *str2); 

程式例:

#include

#include

#include

int main(void) 

22.函式名: strstr 

功  能: 在串中查詢指定字串的第一次出現 

用  法: char *strstr(char *str1, char *str2); 

程式例:

#include

#include

int main(void) 

23.函式名: strtod 

功  能: 將字串轉換為double型值 

用  法: double strtod(char *str, char **endptr); 

程式例:

#include

#include

int main(void) 

24.函式名: strtok 

功  能: 查詢由在第二個串中指定的分界符分隔開的單詞 

用  法: char *strtok(char *str1, char *str2); 

程式例:

#include

#include

int main(void) 

25.函式名: strtol 

功  能: 將串轉換為長整數 

用  法: long strtol(char *str, char **endptr, int base); 

程式例:

#include

#include

int main(void) 

26.函式名: strupr 

功  能: 將串中的小寫字母轉換為大寫字母 

用  法: char *strupr(char *str); 

程式例:

#include

#include

int main(void) 

27.函式名: swab 

功  能: 交換位元組 

用  法: void swab (char *from, char *to, int nbytes); 

程式例:

#include

#include

#include

char source[15] = "rfna koblrna d"; 

char target[15];

int main(void) 

C語言字串操作函式

引用自 1.字串反轉 strrev 2.字串複製 strcpy 3.字串轉化為整數 atoi 4.字串求長 strlen 5.字串連線 strcat 6.字串比較 strcmp 7.計算字串中的母音字元個數 8.判斷乙個字串是否是回文 1.寫乙個函式實現字串反轉 版本1 while版 void st...

C語言字串操作函式

c語言字串操作函式 1.字串反轉 strrev 2.字串複製 strcpy 3.字串轉化為整數 atoi 4.字串求長 strlen 5.字串連線 strcat 6.字串比較 strcmp 7.計算字串中的母音字元個數 8.判斷乙個字串是否是回文 1.寫乙個函式實現字串反轉 版本1 while版 v...

C語言字串操作函式

c語言字串操作函式 1.字串反轉 strrev 2.字串複製 strcpy 3.字串轉化為整數 atoi 4.字串求長 strlen 5.字串連線 strcat 6.字串比較 strcmp 7.計算字串中的母音字元個數 8.判斷乙個字串是否是回文 1.寫乙個函式實現字串反轉 版本1 while版 v...