C語言專題——標準庫

C語言專題——標準庫<string.h>

1 複製
 
char* strcpy (char *s1, const char *s2);
將字符串s2複製到s1指定的地址
 
char* strncpy (char *s1, const char *s2, size_t len);
void*  memcpy (void *s1, const void *s2, size_t len);
將s2的前len個字符(字節)複製到s1中指定的地址, 不加'\0'
 
void* memmove (void *s1, const void *s2, size_t len);
當源單元和目的單元緩衝區交迭時使用
 
size_t strxfrm (char *s1, const char *s1, size_t len);
根據程序當前的區域選項, 將s2的前len個字符(字節)複製到s1中指定的地址, 不加'\0'
 

2 鏈接
 
char* strcat (char *s1, const char *s2);
將字符串s2鏈接到s1尾部
 
char* strncat (char *s1, const char *s2, size_t len);
將字符串s2的前len個字符鏈接到s1尾部, 不加'\0'
 

3 比較
 
int strcmp (const char *s1, const char *s2);
比較字符串s1和s2
 
int strncmp (const char *s1, const char *s2, size_t len);
int  memcmp (const void *s1, const void *s2, size_t len);
對s1和s2的前len個字符(字節)做比較
 
int strcoll (const char *s1, const char *s2);
根據程序當前的區域選項中的LC_COLLATE, 比較字符串s1和s2
 

4 查找
 
char* strchr (const char *s, int ch);
void* memchr (const void *s, int ch, size_t len);
在s中查找給定字符(字節值)ch第一次出現的位置
 
char* strrchr (const char *s, int ch);
在串s中查找給定字符ch最後一次出現的位置, r表示從串尾開始
 
char* strstr (const char *s1, const char *s2);
在串s1中查找指定字符串s2第一次出現的位置
 
size_t strspn (const char *s1, const char *s2);
返回s1中第一個在s2中不存在的字符的索引(find_first_not_of)
 
size_t strcspn (const char *s1, const char *s2);
返回s1中第一個也在s2中存在的字符的索引(find_first_of)
 
char* strpbrk (const char *s1, const char *s2);
與strcspn相似, 區別是返回指針而不是索引
 
char* strtok (char *s1, const char *s2);
從串s1中分離出由串s2中指定的分界符分隔開的記號(token)
第一次調用時s1爲需分割的字串, 此後每次調用都將s1置爲NULL,
每次調用strtok返回一個記號, 直到返回NULL爲止
 

5 其餘
 
size_t strlen (const char *s);
求字符串s的長度
 
void* memset (void *s, int val, size_t len);
將從s開始的len個字節置爲val
 
char* strerror (int errno);
返回指向錯誤信息字符串的指針
 
source: 《C & C++ Code Capsules》
相關文章
相關標籤/搜索