把自己学习C语言的技巧记录下来,以免忘记,每天至少一更
File I/O
1. Size of File Descriptor Table is limited. Make sure to close file descriptor when read and write in a large number of times.
2. Use following format to read and write content from/to files:
byte_read = read(infd, buf, BLKSIZE);
...
write(outfd, buf, byte_read);
Optimization
1. Use local variable rather than dynamic memory allocation to prevent memory leak.
String
1. Do not use equal sign, use strcpy instead.
2. 当在函数中初始化一个local char* 时,用bzero初始化
定义含有自身type的struct时, 直接用struct + 自身type。
typedef struct queue_node {
char* client;
struct queue_node *next;
} queue_node_t;
本文分享了作者在学习C语言过程中的实用技巧,包括文件输入输出(File I/O)的最佳实践、优化建议以及字符串处理注意事项等。文章还介绍了如何定义包含自身类型的结构体(struct),并给出了具体的代码示例。
1297

被折叠的 条评论
为什么被折叠?



