链表的问题
# include <stdio.h># include <malloc.h>
# define LEN sizeof(struct train)
# define NULL 0
struct train
{
int num;
struct train *next;
}
void print (struct train *head);
void count (struct train *head);
int main()
{
int n=0;
struct train *head,*p1,*p2;
p1=p2=(struct train *) malloc(LEN);
head=NULL;
scanf("%d",&p1->num);
while (p1->num !=0)
{
n++;
if (n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct train *) malloc(LEN);
scanf("%d",&p1->num);
}
p2->next=NULL;
print(head);
count(head);
return 0;
}
void print (struct train *head)
{
struct train *tmp;
tmp=head;
if (head !=NULL)
do
{printf("%d ",tmp->num);
tmp=tmp->next;
}while (tmp !=NULL);
printf("\n");
}
void count (struct train *head)
{
int count=0;
struct train *tmp;
tmp=head;
if (head !=NULL)
do
{count++;
}while (tmp->next !=NULL);
printf("%d\n",count);
}
编译过程提示错误:
error C2628: “train”后面接“void”是非法的(是否忘记了“;”?)
error C2556: “void print(train *)”: 重载函数与“train print(train *)”只是在返回类型上不同
error C2371: “print”: 重定义;不同的基类型
这是什么错误?