C庫函數中字串處理函數集合

來源:互聯網
上載者:User

C庫函數中字串處理函數集合
 

bcmp

原型:extern int bcmp(const void *s1, const void *s2, int n);
用法:#include <string.h>
功能:比較字串s1和s2的前n個位元組是否相等
說明:如果s1=s2或n=0則返回零,否則返回非零值。bcmp不檢查NULL。

bcopy   

原型:extern void bcopy(const void *src, void *dest, int n);
用法:#include <string.h>
   功能:將字串src的前n個位元組複製到dest中
   說明:bcopy不檢查字串中的空位元組NULL,函數沒有傳回值。

bzero

   原型:extern void bzero(void *s, int n);
   用法:#include <string.h>
   功能:置位元組字串s的前n個位元組為零。
   說明:bzero無傳回值。

memccpy  

   原型:extern void *memccpy(void *dest, void *src, unsigned char ch, unsigned int count);
   用法:#include <string.h>
   功能:由src所指記憶體地區複製不多於count個位元組到dest所指記憶體地區,如果遇到字元ch則停止複製。
   說明:返回指向字元ch後的第一個字元的指標,如果src前n個位元組中不存在ch則返回NULL。ch被複製。
 
memchr 

   原型:extern void *memchr(void *buf, char ch, unsigned count);
   用法:#include <string.h>
   功能:從buf所指記憶體地區的前count個位元組尋找字元ch。
   說明:當第一次遇到字元ch時停止尋找。如果成功,返回指向字元ch的指標;否則返回NULL。

memcmp

   原型:extern int memcmp(void *buf1, void *buf2, unsigned int count);     
   用法:#include <string.h>
   功能:比較記憶體地區buf1和buf2的前count個位元組。
   說明:
         當buf1<buf2時,傳回值<0
         當buf1=buf2時,傳回值=0
         當buf1>buf2時,傳回值>0

memcpy

   原型:extern void *memcpy(void *dest, void *src, unsigned int count);
用法:#include <string.h>
   功能:由src所指記憶體地區複製count個位元組到dest所指記憶體地區。
   說明:src和dest所指記憶體地區不能重疊,函數返回指向dest的指標。

memicmp
 
   原型:extern int memicmp(void *buf1, void *buf2, unsigned int count);     
   用法:#include <string.h>
   功能:比較記憶體地區buf1和buf2的前count個位元組但不區分字母的大小寫。
   說明:memicmp同memcmp的唯一區別是memicmp不區分大小寫字母。
         當buf1<buf2時,傳回值<0
         當buf1=buf2時,傳回值=0
         當buf1>buf2時,傳回值>0

memmove
 
   原型:extern void *memmove(void *dest, const void *src, unsigned int count);    
   用法:#include <string.h>
   功能:由src所指記憶體地區複製count個位元組到dest所指記憶體地區。
   說明:src和dest所指記憶體地區可以重疊,但複製後src內容會被更改。函數返回指向dest的指標。

memset

   原型:extern void *memset(void *buffer, int c, int count);     
   用法:#include <string.h>
   功能:把buffer所指記憶體地區的前count個位元組設定成字元c。
   說明:返回指向buffer的指標。

movmem 

   原型:extern void movmem(void *src, void *dest, unsigned int count);     
   用法:#include <string.h>
   功能:由src所指記憶體地區複製count個位元組到dest所指記憶體地區。
   說明:src和dest所指記憶體地區可以重疊,但複製後src內容會被更改。函數返回指向dest的指標。

setmem

   原型:extern void setmem(void *buf, unsigned int count, char ch);     
   用法:#include <string.h>
   功能:把buf所指記憶體地區前count個位元組設定成字元ch。
   說明:返回指向buf的指標。

stpcpy
 
   原型:extern char *stpcpy(char *dest,char *src);   
   用法:#include <string.h>
   功能:把src所指由NULL結束的字串複製到dest所指的數組中。
   說明:src和dest所指記憶體地區不可以重疊且dest必須有足夠的空間來容納src的字串。
         返回指向dest結尾處字元(NULL)的指標。

strcat

   原型:extern char *strcat(char *dest,char *src);     
   用法:#include <string.h>
   功能:把src所指字串添加到dest結尾處(覆蓋dest結尾處的'/0')並添加'/0'。
   說明:src和dest所指記憶體地區不可以重疊且dest必須有足夠的空間來容納src的字串。
         返回指向dest的指標。

strchr 

   原型:extern char *strchr(char *s,char c);  
   用法:#include <string.h>
   功能:尋找字串s中首次出現字元c的位置
   說明:返回首次出現c的位置的指標,如果s中不存在c則返回NULL。
 
strcmp
  
   原型:extern int strcmp(char *s1,char * s2);   
   用法:#include <string.h>
   功能:比較字串s1和s2。
   說明:
         當s1<s2時,傳回值<0
         當s1=s2時,傳回值=0
         當s1>s2時,傳回值>0

stricmp,strcmpi  

   原型:extern int stricmp(char *s1,char * s2);     
   用法:#include <string.h>
   功能:比較字串s1和s2,但不區分字母的大小寫。
   說明:strcmpi是到stricmp的宏定義,實際未提供此函數。
         當s1<s2時,傳回值<0
         當s1=s2時,傳回值=0
         當s1>s2時,傳回值>0

strcpy
 
   原型:extern char *strcpy(char *dest,char *src);   
   用法:#include <string.h>
   功能:把src所指由NULL結束的字串複製到dest所指的數組中。
   說明:src和dest所指記憶體地區不可以重疊且dest必須有足夠的空間來容納src的字串。
         返回指向dest的指標。

strcspn

   原型:extern int strcspn(char *s1,char *s2);    
   用法:#include <string.h>
   功能:在字串s1中搜尋s2中所出現的字元。
   說明:返回第一個出現的字元在s1中的下標值,亦即在s1中出現而s2中沒有出現的子串的長度。

strdup
  
   原型:extern char *strdup(char *s);    
   用法:#include <string.h>
   功能:複製字串s
   說明:返回指向被複製的字串的指標,所需空間由malloc()分配且可以由free()釋放。

strlen
 
   原型:extern int strlen(char *s);     
   用法:#include <string.h>
   功能:計算字串s的長度
   說明:返回s的長度,不包括結束符NULL。

strlwr

   原型:extern char *strlwr(char *s);     
   用法:#include <string.h>
   功能:將字串s轉換為小寫形式
   說明:只轉換s中出現的大寫字母,不改變其它字元。返回指向s的指標。

strncat

   原型:extern char *strncat(char *dest,char *src,int n);     
   用法:#include <string.h>
   功能:把src所指字串的前n個字元添加到dest結尾處(覆蓋dest結尾處的'/0')並添加'/0'。
   說明:src和dest所指記憶體地區不可以重疊且dest必須有足夠的空間來容納src的字串。
         返回指向dest的指標。

strncmp

   原型:extern int strcmp(char *s1,char * s2,int n);    
   用法:#include <string.h>
   功能:比較字串s1和s2的前n個字元。
   說明:
         當s1<s2時,傳回值<0
         當s1=s2時,傳回值=0
         當s1>s2時,傳回值>0

strnicmp,strncmpi

   原型:extern int strnicmp(char *s1,char * s2,int n);   
   用法:#include <string.h>
   功能:比較字串s1和s2的前n個字元但不區分大小寫。
   說明:strncmpi是到strnicmp的宏定義
         當s1<s2時,傳回值<0
         當s1=s2時,傳回值=0
         當s1>s2時,傳回值>0

strncpy
  
   原型:extern char *strncpy(char *dest, char *src, int n);     
   用法:#include <string.h>
   功能:把src所指由NULL結束的字串的前n個位元組複製到dest所指的數組中。
   說明:
         如果src的前n個位元組不含NULL字元,則結果不會以NULL字元結束。
         如果src的長度小於n個位元組,則以NULL填充dest直到複製完n個位元組。
         src和dest所指記憶體地區不可以重疊且dest必須有足夠的空間來容納src的字串。
         返回指向dest的指標。

strpbrk

   原型:extern char *strpbrk(char *s1, char *s2);     
   用法:#include <string.h> 
   功能:在字串s1中尋找字串s2中任何一個字元相匹配的第一個字元的位置,Null 字元NULL不包括在內。 
   說明:返回指向s1中第一個相匹配的字元的指標,如果沒有匹配字元則返回null 指標NULL。

strrev
 
   原型:extern char *strrev(char *s);      
   用法:#include <string.h>
   功能:把字串s的所有字元的順序顛倒過來(不包括Null 字元NULL)。
   說明:返回指向顛倒順序後的字串指標。

strset

   原型:extern char *strset(char *s, char c);     
   用法:#include <string.h>
   功能:把字串s中的所有字元都設定成字元c。
   說明:返回指向s的指標。

strstr

   原型:extern char *strstr(char *haystack, char *needle);    
   用法:#include <string.h>
   功能:從字串haystack中尋找needle第一次出現的位置(不比較結束符NULL)。
   說明:返回指向第一次出現needle位置的指標,如果沒找到則返回NULL。

strtok

   原型:extern char *strtok(char *s, char *delim);     
   用法:#include <string.h>
   功能:分解字串為一組標記串。s為要分解的字串,delim為分隔字元字串。
   說明:首次調用時,s必須指向要分解的字串,隨後調用要把s設成NULL。
         strtok在s中尋找包含在delim中的字元並用NULL('/0')來替換,直到找遍整個字串。
         返回指向下一個標記串。當沒有標記串時則返回Null 字元NULL。

strupr

   原型:extern char *strupr(char *s);     
   用法:#include <string.h>
   功能:將字串s轉換為大寫形式
   說明:只轉換s中出現的小寫字母,不改變其它字元。返回指向s的指標。

本文來自CSDN部落格,轉載請標明出處:http://blog.csdn.net/general1982/archive/2009/03/21/4012566.aspx

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.