c字串函式總結

2021-12-29 20:41:18 字數 4106 閱讀 5973

4. memccpy

原型:extern void *memccpy(void *dest, void *src, unsigned char ch, unsigned int count);

用法:#include

功能:由src所指記憶體區域複製不多於count個位元組到dest所指記憶體區域,如果遇到字元ch則停止複製。

說明:返回指向字元ch後的第乙個字元的指標,如果src前n個位元組中不存在ch則返回null。ch被複製。

5. memchr

原型:extern void *memchr(void *buf, char ch, unsigned count);

用法:#include

功能:從buf所指記憶體區域的前count個位元組查詢字元ch。

說明:當第一次遇到字元ch時停止查詢。如果成功,返回指向字元ch的指標;否則返回null。

6.memicmp

原型:extern int memicmp(void *buf1, void *buf2, unsigned int count);

用法:#include

功能:比較記憶體區域buf1和buf2的前count個位元組但不區分字母的大小寫。

說明:memicmp同memcmp的唯一區別是memicmp不區分大小寫字母。

當buf1

當buf1=buf2時,返回值=0

當buf1>buf2時,返回0

7.memmove

原型:extern void *memmove(void *dest, const void *src, unsigned int count);

用法:#include

功能:由src所指記憶體區域複製count個位元組到dest所指記憶體區域。

說明:src和dest所指記憶體區域可以重疊,但複製後src內容會被更改。函式返回指向dest的指標。

8.memset

原型:extern void *memset(void *buffer, int c, int count);

用法:#include

功能:把buffer所指記憶體區域的前count個位元組設定成字元c。

說明:返回指向buffer的指標。

9. movmem

原型:extern void movmem(void *src, void *dest, unsigned int count);

用法:#include

功能:由src所指記憶體區域複製count個位元組到dest所指記憶體區域。

說明:src和dest所指記憶體區域可以重疊,但複製後src內容會被更改。函式返回指向dest的指標。

10.setmem

原型:extern void setmem(void *buf, unsigned int count, char ch);

用法:#include

功能:把buf所指記憶體區域前count個位元組設定成字元ch。

說明:返回指向buf的指標。

11.stpcpy

原型:extern char *stpcpy(char *dest,char *src);

用法:#include

功能:把src所指由null結束的字串複製到dest所指的陣列中。

說明:src和dest所指記憶體區域不可以重疊且dest必須有足夠的空間來容納src的字串。

返回指向dest結尾處字元(null)的指標。

12.原型:extern char *strcat(char *dest,char *src);

用法:#include

功能:把src所指字串新增到dest結尾處(覆蓋dest結尾處的'\0')並新增'\0'。

說明:src和dest所指記憶體區域不可以重疊且dest必須有足夠的空間來容納src的字串。

返回指向dest的指標。

13.strchr

原型:extern char *strchr(char *s,char c);

用法:#include

功能:查詢字串s中首次出現字元c的位置

說明:返回首次出現c的位置的指標,如果s中不存在c則返回null。

14.strcmp

原型:extern int strcmp(char *s1,char * s2);

用法:#include

功能:比較字串s1和s2。

說明:當s1

當s1=s2時,返回值=0

當s1>s2時,返回0

15. strcmpi

原型:extern int stricmp(char *s1,char * s2);

用法:#include

功能:比較字串s1和s2,但不區分字母的大小寫。

說明:strcmpi是到stricmp的巨集定義,實際未提供此函式。

當s1當s1=s2時,返回值=0

當s1>s2時,返回0

16.strcpy

原型:extern char *strcpy(char *dest,char *src);

用法:#include

功能:把src所指由null結束的字串複製到dest所指的陣列中。

說明:src和dest所指記憶體區域不可以重疊且dest必須有足夠的空間來容納src的字串。

返回指向dest的指標。

17. strcspn

原型:extern int strcspn(char *s1,char *s2);

用法:#include

功能:在字串s1中搜尋s2中所出現的字元。

說明:返回第乙個出現的字元在s1中的下標值,亦即在s1**現而s2中沒有出現的子串的長度.

18.strdup

原型:extern char *strdup(char *s);

用法:#include

功能:複製字串s

說明:返回指向被複製的字串的指標,所需空間由malloc()分配且可以由free()釋放。

19.stricmp

原型:extern int stricmp(char *s1,char * s2);

用法:#include

功能:比較字串s1和s2,但不區分字母的大小寫。

說明:strcmpi是到stricmp的巨集定義,實際未提供此函式。

當s1當s1=s2時,返回值=0

當s1>s2時,返回0

20.strlen

原型:extern int strlen(char *s);

用法:#include

功能:計算字串s的長度

說明:返回s的長度,不包括結束符null。

21.strlwr

原型:extern char *strlwr(char *s);

用法:#include

功能:將字串s轉換為小寫形式

說明:只轉換s**現的大寫字母,不改變其它字元。返回指向s的指標。

22.strncat

原型:extern char *strncat(char *dest,char *src,int n);

用法:#include

功能:把src所指字串的前n個字元新增到dest結尾處(覆蓋dest結尾處的'\0')並新增'\0'。

說明:src和dest所指記憶體區域不可以重疊且dest必須有足夠的空間來容納src的字串。

返回指向dest的指標。

23.strncmp

原型:extern int strcmp(char *s1,char * s2,int n);

用法:#include

功能:比較字串s1和s2的前n個字元。

說明:當s1

當s1=s2時,返回值=0

當s1>s2時,返回0

24.strncmpi

原型:extern int strnicmp(char *s1,char * s2,int n);

用法:#include

功能:比較字串s1和s2的前n個字元但不區分大小寫。

說明:strncmpi是到strnicmp的巨集定義

當s1當s1=s2時,返回值=0

當s1>s2時,返回0

25.strncpy

原型:extern char *strncpy(char *dest,

摘自 永爭一流,我的信仰!

C語言字串函式總結

用法 size t strlen const char s 返回字串s的長度,不包括結尾的 0 include include int main int argc,char argv result strlen 5 sizeof 6 include include int mylen const c...

c語言字串函式總結

1.字串連線函式strcat extern char strcat char dest,const char src include 把src所指向的字串 包括 0 複製到dest所指向的字串後面 刪除 dest原來末尾的 0 要保證 dest足夠長,以容納被複製進來的 src。src中原有的字元不...

C語言 字串函式總結

陣列和指標 陣列和指標的區別 字串陣列 指標和字串 字串輸入 scanf 函式 字串輸出 字串函式 ctype.h中的函式 寫在前面 本文基於上課所用ppt及 c primer plus 第6版,也是多源於此。字串函式一直是本人弱項,終於熬過了考試周,來總結一下為c語言的期末機試做準備。字串 以 空...