C_str的入门级notes
生活随笔
收集整理的這篇文章主要介紹了
C_str的入门级notes
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
嗯,受人所托,順便整理的
英文渣
侵刪。
// 注釋的部分是解說(廢話)和不怎么重(kǎo)要(chá)的
錯誤請指正
#include <stdio.h> #include <string.h> int main() {char str[] = "sstr";// "sstr." == 's', 's', 't', 'r', '\0'// without a '\0' it's usually not considered a c-style string// but a normal array of type char// many lib funcs need '\0' to identify a complete string
printf("%s\n", sstr);scanf("%s", sstr); // stops reading when meets a spaceprintf("\n%s\n", sstr);gets(str); // reads a full line until a '\n' // ('\n' not included)// puts(char[]) is less used, automatically '\n'int len = strlen(sstr); // '\0' not included// strcat(aimStr, sourceStr); // 2 '\0' needed and 1 remains// strcat(aimStr, sourceStr, n); // only n bytes// strcpy(aimStr, sourceStr (, n));// strcmp(strA, strB (, n)); // strA-strB (the first n bits)// ascii bigger, string bigger// the longer, the bigger// strlwr(sstr); strupr(sstr);newStr = strstr(char* text, char* match);// char* arrayAddress = strrev(sstr);// strset etc, recommeding memset(void* _Dst, int _Val, size_t _Size);// mem.h or string.hdouble doublePrecision = strtod(strFloat, &endptr);// atoi,atol,strtod,strtol,strtoul// proto: longstrtol(char *str, char **endptr, int base);// for ioc = getchar(); // dangerous, '\n' and all asciis untouchedgets(sstr); // '\n' is read and replaced by '\0'scanf(... , someStr) // buf still holds '\n', ' ', etcscanf(... , &someChar) // close to getchar()// for formatted io, related sources:// http://www.jb51.net/article/62358.htm// http://baike.baidu.com/link?url=Ijwdh1w3qXfTtff-WlPW1QowBiaCgE7zjVHAOT35VHDXtmz3MmQhPk7zs-_pc1_7rI9-AZRZr60hWlgzPeUzQa// focus: operator precedence// file io is important but not in the range }
by(無'\0')
by 百毒百科
轉載于:https://www.cnblogs.com/witchelny-ravens/p/5077295.html
總結
以上是生活随笔為你收集整理的C_str的入门级notes的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 雪佛兰科鲁兹发动机皮带多久换
- 下一篇: Linux命令学习总结:hexdump