C语言链表尾部插入新节点的问题
#include<stdio.h>#include<stdlib.h>
#include<strings.h>
struct node
{
int data;
struct node *pnext;
};
struct node *create_node(int);
void insert_tail(struct node *,struct node *);
int main()
{
struct node *pheader = create_node(0);
insert_tail(pheader,create_node(1));
insert_tail(pheader,create_node(2));
insert_tail(pheader,create_node(3));
printf("header node data = %d\n",pheader->data);
printf("node 1 data = %d\n",pheader->pnext->data);
printf("node 2 data = %d\n",pheader->pnext->pnext->data);
printf("node 3 data = %d\n",pheader->pnext->pnext->pnext->data);
}
struct node *create_node(int data)
{
struct node * p = (struct node*)malloc(sizeof(struct node));
if(NULL == p)
{
printf("malloc error!\n");
return NULL;
}
memset(p,0,sizeof(struct node));
p->data = data;
p->pnext = NULL;
return p;
}
void insert_tail(struct node *ph,struct node *new) [Error] expected ',' or '...' before 'new'
{
int count = 0;
while(NULL != ph)
{
ph = ph->pnext;
count++;
}
ph->pnext = new; [Error] expected type-specifier before ';' token
ph->data = count + 1;
}
这是C语言链表尾部插入新节点的程序,但运行时总是出现2个错误,分别是上面两处红色部分,我改了好久也没有成功,希望大佬能给我提供点帮助。