一个链表的问题

houqidian 2009-09-09 10:09:26
#include <stdio.h>
#include <stdlib.h>
struct node
{
int num;
struct node *next;
};
int main()
{
struct node *creat();
void print();
struct node *head;
head=NULL;
head=creat(head);
print(head);
return 0;
}
struct node *creat(struct node *head)
{
int n;
struct node *p1=NULL,*p2=NULL;
printf("\n Please input a integer(>0),if input -1 then exit:\n");
scanf("%d",&n);
while(n>0)
{
p1=(struct node*)malloc(sizeof(struct node));
p1->num=n;
p1->next =NULL;
if(head==NULL)
head=p1;
else
p2->next=p1;
p2=p1;
scanf("%d",&n);
}
return head;
}
void print(struct node *head)
{
struct node *temp;
temp=head;
while(temp!=NULL)
{
printf("%6d",temp->num);
temp=temp->next ;
}
}
哪位大侠帮我看看,在vc++2008上运行有两个错误,怎么解决
error C2660: “creat”: 函数不接受 1 个参数
error C2660: “print”: 函数不接受 1 个参数

...全文
54 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
mstlq 2009-09-09
  • 打赏
  • 举报
回复

#include <stdio.h>
#include <stdlib.h>
struct node
{
int num;
struct node *next;
};
int main()
{
struct node *creat(struct node *);//mark
void print(struct node *);//mark
struct node *head;
head=NULL;
head=creat(head);
print(head);
return 0;
}
struct node *creat(struct node *head)
{
int n;
struct node *p1=NULL,*p2=NULL;
printf("\n Please input a integer(>0),if input -1 then exit:\n");
scanf("%d",&n);
while (n>0)
{
p1=(struct node*)malloc(sizeof(struct node));
p1->num=n;
p1->next =NULL;
if (head==NULL)
head=p1;
else
p2->next=p1;
p2=p1;
scanf("%d",&n);
}
return head;
}
void print(struct node *head)
{
struct node *temp;
temp=head;
while (temp!=NULL)
{
printf("%6d",temp->num);
temp=temp->next ;
}
}
houqidian 2009-09-09
  • 打赏
  • 举报
回复
已经解决了,谢谢
hoomey 2009-09-09
  • 打赏
  • 举报
回复

/*
int main()
{
struct node *creat();
void print();
*/
struct node *creat();
void print();
int main()
{



函数声明放错地方了
brookmill 2009-09-09
  • 打赏
  • 举报
回复
int main()
{
struct node *creat(struct node *);
void print(struct node *);

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧