链表如下:
struct ipaddr_t
{
int size;
char* ipaddr
};
struct msg_t
{
int size;
char* msg;
};
struct node_t
{
int port;
struct ipaddr_t* ipaddr_h;
struct msg_t* msg;
struct node_t* next;
};
http://www.cnblogs.com/scrat/archive/2012/08/14/2638740.html
我是这么写的,但是不知道对不对? 望高手们解答,谢谢!
static node_h node_creat(node_h node)
{
int i = 0;
node_h p1, p2;
p1 = p2 = (node_h)malloc(sizeof(struct node_t));
if(p1 == NULL || p2 == NULL)
{
return NULL;
}
memset(p1, 0, sizeof(struct node_t));
for(i=0;i<2;i++)
{
scanf("%d", &p1->port);
p1->ipaddr_h = ipaddr_input(p1->ipaddr_h);
p1->msg_h = msg_input(p1->msg_h);
p1->next = NULL;
if(node == NULL)
{
node = p1;
}
else{
p2->next = p1;
}
p2 = p1;
p1 = (node_h)malloc(sizeof(struct node_t));
if(p1 == NULL)
{
return NULL;
}
}
return node;
}
static struct ipaddr_t* ipaddr_input(struct ipaddr_t* ipaddr_h)
{
ipaddr_h = ipaddr_new(sizeof(struct ipaddr_t));
scanf("%d", &ipaddr_h->size);
ipaddr_h->ipaddr = malloc(ipaddr_h->size);
if(ipaddr_h->ipaddr == NULL)
{
return NULL;
}
memset(ipaddr_h->ipaddr, 0, ipaddr_h->size);
scanf("%s", ipaddr_h->ipaddr);
return ipaddr_h;
}
static struct msg_t* msg_input(struct msg_t* msg_h)
{
msg_h = msg_new(sizeof(struct msg_t));
scanf("%d", &msg_h->size);
msg_h->msg = malloc(msg_h->size);
if(msg_h->msg == NULL)
{
return NULL;
}
memset(msg_h->msg, 0, msg_h->size);
scanf("%s", msg_h->msg);
return msg_h;
}
...new 和delete没写进去..
这样写对嘛?