<1> 把null结尾的字符串转换成整数
#include <stdlib.h>
int atoi(const char *nptr);
long atol(const char *nptr);
long long atoll(const char *nptr);
<2>如何开启关闭打印信息
#ifdef DEBUG
#define dbg_prt(fmt,arg...) printf(fmt,##arg)
#else
#define dbg_prt(fmt,arg...)
#endif
<3>一个把node插入链表尾部的小技巧
假设一个struct node{
struct node* next;
};的链表。头结点为struct node* head_node;
如何把一个新的node插入到该链表的尾部呢。
一般方法:
for(p=head_node; p!=NULL; p=p->next)
{
q=p;//必须另外声明个指针来记录p的位置。以免走到尾部丢失了前结点信息。
}
q->next=node;//把node插入到链表的尾部。
新方法是采用指针的指针:
for(p=&head_node;*p; p=&(*p)->next)
{
}
(*p)=node; //把结点插入到链表的尾部。相当于把node地址写入到*p变量里。