第九章 字符串,字符和字节
1.NUL字節是字符串終止符,但它本身并不是字符串的一部分,所以字符串的長度并不包括NUL字節。
?
2.size_t這個類型是在頭文件stddef.h中定義的,返回長度。
?
3.連接字符串:strcat
strcpy(message,"hello"); strcat(message,customer_name); strcat(message,",how are you?");hello,how are you?
strcat(strcpy(dat,a),b);ab
?
4.字符串比較(字典比較):比較ASCII碼大小 ? strcmp
?
5.NUL相當于‘\0’,結束字符串,前者為字符常量的名字,后者相當于是字符串常量
?
? NULL在stddef.h中專門為空指針定義的一個宏(void *)0
?
6.strlen不包含'\0',strcpy會把'\0'復制過去。
strlen返回字符串長度時,不會把字符串長度返回過去。
?
7.長度受限的字符串函數:strncpy.......char *strncpy(char *dst, char const *src, size_t len) ?向dst中寫入len個字符,如果被復制字符串小于len個字符,則將用NUL補充至len個。如果大于或等于,結果不會有NUL所以需要自己加上‘\0’。
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?strncat.......char *strncat(char *dst, char *src,size_t len)總是在結果字符串后面添加NUL字節,而且它不會像strncpy那樣對目標數組用NUL字節進行填充。
?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?strncmp........int strncmp(char const *s1,char const *s2, char const *s3)只對前len個進行比較。
?
8.字符串查找:
查找一個字符:strchr,strrchr ? ? ? ? ? ? ? ? ? ? ? ??查找任何幾個字符:strpbrk
?
查找一個子串:strstr ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??查找一個字符串前綴:strspn,strcspn
?
查找標記:strtok ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 錯誤信息:strerror
?
字符轉換:tolower,toupper ? ? ? ? ? ? ? ? ? ? ? ? ? 內存操作:memcpy(復制),memchr(查找),memset(設置(初始化等))
?
字符串分類:iscnstrl.....
?
9.在使用strcpy和strcat時要考慮容器夠大,否則會溢出。
?
轉載于:https://www.cnblogs.com/Mayfly-nymph/p/8372926.html
總結
以上是生活随笔為你收集整理的第九章 字符串,字符和字节的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 创建pod步骤
- 下一篇: 十进制转换成二进制列表