<cstring>頭文件
函數 strcpy
- 原型: char* strcpy (char *s1, const char *s2);
- 作用: 將字符串 2 複製到字符數組 1 當中去
- 說明:
- 字符數組 1 的長度應不小於字符串2的長度
- "字符數組 1" 必須寫成數組名形式,"字符串 2" 可以爲字符數組名,也可以是一個字符串常量
- 在未對字符數組 1 賦初值時,複製時將 "字符串 2" 中的字符串和其後的 "/0" 一起復制到字符數組 1 中,取代其前 n+1 個字符,而後面的字符是 "字符數組 1" 原字符
函數 strncpy
- 原型: char* strncpy (char *s1, const char *s2, size_t len);
- 作用: 將 s2 的前 len 個字符複製到 s1 中指定的地址, 不加 '\0'
函數 memcpy
- 原型: void* memcpy (void *s1, const void *s2, size_t len);
- 作用: 將 s2 的前 len 個字節複製到 s1 中指定的地址, 不加 '\0'
- 說明: 源和目的不能是同一塊內存區域
函數 memmove
- 原型: void* memmove (void *s1, const void *s2, size_t len);
- 作用: 當源單元和目的單元緩衝區交迭時使用
- 說明: 源和目的可以是同一塊內存區域(例如數組某個元素在數組存儲器內部移動數據)
函數 strxfrm
- 原型: size_t strxfrm (char *s1, const char *s1, size_t len);
- 作用: 根據程序當前的區域選項,將 s2 的前 len 個字符(字節)複製到 s1 中指定的地址, 不加 '\0'
函數 strcat
- 原型: char* strcat (char *s1, const char *s2);
- 作用: 把字符串 2 接到字符串 1 後面(字符串 1 要足夠大)
- 說明: 連接前兩個字符串都有 "/0" ,連接時將字符串1後 "/0" 丟棄,只在新字符串後保留 '/0'
函數 strncat
- 原型:char* strncat (char *s1, const char *s2, size_t len);
- 作用: 將字符串 s2 的前 len 個字符連接到 s1 尾部, 不加 '\0'
函數 strcmp
- 原型: int strcmp (const char *s1, const char *s2); ①作用:比較字符串1與字符串2
- 規律: 兩個字符串自左至右逐個字符相比(按 ASCII 碼值大小比較)直到出現不同的字符或者遇到 "/0" 爲止,如果全部字符相同,則認爲相等,若出現不同字符,則以第一個不相同的字符爲準
- 準則:
- 如果字符串 1=字符串 2,函數返回值爲 0
- 如果字符串 1>字符串 2,函數返回值爲正數
- 如果字符串1<字符串 2,函數返回值爲負數
函數 strncmp
- 原型: int strncmp (const char *s1, const char *s2, size_t len);
- 作用: 對 s1 和 s2 的前len個字符作比較
函數 memcmp
- 原型: int memcmp (const void *s1, const void *s2, size_t len);
- 作用: 對 s1 和 s2 的前 len 個字節作比較
函數 strcoll
- 原型: int strcoll (const char *s1, const char *s2);
- 作用: 根據程序當前的區域選項中的 LC_COLLATE, 比較字符串 s1 和 s2
函數 strchr
- 原型: char* strchr (const char *s, int ch);
- 作用: 在 s 中查找給定字符 ch 第一次出現的位置
函數 memchr
- 原型: void* memchr (const void *s, int ch, size_t len);
- 作用: 查找在字符串中最後一次出現字符 ’ch’ 的位置。如果 s 中存在字符 ch,返回出現 ch 的位置的指針;否則返回NULL。
函數 strrchr
- 原型: char* strrchr (const char *s, int ch);
- 作用: 在串 s 中查找給定字符 ch 最後一次出現的位置, r表示從串尾開始
函數 strstr
- 原型: char* strstr (const char *s1, const char *s2);
- 作用: 在串 s1 中查找指定字符串 s2 第一次出現的位置
函數 strspn
- 原型: size_t strspn (const char *s1, const char *s2);
- 作用: 返回一個長度,這個長度是在 s1 中沒有出現 s2 任意字符的從 s1 頭計算的字符串的長度。
函數 strcspn
- 原型: size_t strcspn (const char *s1, const char *s2);
- 作用: 返回一個長度,這個長度是在 s1 中沒有出現 s2 任意字符的從 s1 頭計算的字符串的長度。
函數 strpbrk
- 原型: char* strpbrk (const char *s1, const char *s2);
- 作用: 與 strcspn 類似, 區別是返回指針而不是索引
函數 strtok
- 原型: char* strtok (char *s1, const char *s2);
- 函數執行步驟:
- 從串s1中分離出由串 s2 中指定的分界符分隔開的記號(token)
- 第一次調用時 s1 爲需分割的字串, 此後每次調用都將 s1 置爲 NULL,
- 每次調用 strtok 返回一個記號, 直到返回 NULL 爲止
- 作用: 分解字符串爲一組字符串。s 爲要分解的字符串,delim 爲分隔符字符串。實質上的處理是,strtok 在 s 中查找包含在 delim 中的字符並用 NULL(’\0′) 來替換,直到找遍整個字符串。
- 返回值: 從 s 開頭開始的一個個被分割的串。當沒有被分割的串時則返回 NULL。所有 delim 中包含的字符都會被濾掉,並將被濾掉的地方設爲一處分割的節點。
函數 strlen
- 原型: size_t strlen (const char *s);
- 作用: 它是測試字符串長度的函數,函數的值爲字符串中的實際長度(不包括 "/0")
函數 memset
- 原型: void* memset (void *s, int val, size_t len);
- 作用: 將從 s 開始的 len 個字節置爲 val
函數 strerror
- 原型: char* strerror (int errno);
- 作用: 返回指向錯誤信息字符串的指針
函數 _strlwr
- 原型: char *_strlwr( char *string );
- 作用: 把字符串中的大寫字母換成小寫字母
函數 _strupr
- 原型: char *_strupr( char *string );
- 作用: 把字符串中的小寫字母換成大寫字母