#include<stdio.h>
#include<stdlib.h>
#define SIZE sizeof(struct node)
struct node
{
int date;
struct node *next;
};
struct node * initialize(int num)
{
struct node *head;
struct *p1, *p2;
p1=p2=(struct node*)malloc(SIZE);
printf("\nPlease input the valve of the node:\n");
scanf("%d",&p1->data);
head=p1;
while(num>1)
{
p2->next=p1;
p2=p1;
p1=(struct node *)malloc(SIZE);
scanf("%d",&p1->data);
num--;
}
p2->next=p1;
p2=p1;
p2->next=NULL;
return head;
}
void traverse(struct node *head)
{
struct node *p;
printf("\nThe records are:\n");
p=head;
if(head!=NULL)
{
do
{
printf("%d",p->date);
p=p->next;
}while(p!=NULL);
}
printf("\n");
}
int main()
{
printf("Please input the number of nodes in list:");
int numOfNodes=0;
scanf("%d",&numOfNodes);
struct node *head=initialize(numOfNodes);
traverse(head);
return 0;}
改了这两个,编译仍然不能通过
追答#include
#include
#define SIZE sizeof(struct node)
struct node
{
int date;
struct node *next;
};
struct node * initialize(int num)
{
struct node *head;
struct node *p1, *p2;
p1=p2=(struct node*)malloc(SIZE);
printf("\nPlease input the valve of the node:\n");
scanf("%d",&p1->date);
head=p1;
while(num>1)
{
p2->next=p1;
p2=p1;
p1=(struct node *)malloc(SIZE);
scanf("%d",&p1->date);
num--;
}
p2->next=p1;
p2=p1;
p2->next=NULL;
return head;
}
void traverse(struct node *head)
{
struct node *p;
printf("\nThe records are:\n");
p=head;
if(head!=NULL)
{
do
{
printf("%d",p->date);
p=p->next;
}while(p!=NULL);
}
printf("\n");
}
int main()
{
printf("Please input the number of nodes in list:");
int numOfNodes=0;
scanf("%d",&numOfNodes);
struct node *head=initialize(numOfNodes);
traverse(head);
return 0;}
你复制过去看看,我用VS2008没有问题了
(21) : error C2039: 'data' : is not a member of 'node'(8) : see declaration of 'node'(54) : error C2143: syntax error : missing ';' before 'type'(57) : warning C4047: 'function' : 'struct node *' differs in levels of indirection from 'int '(57) : warning C4024: 'traverse' : different types for formal and actual parameter 1Error executing cl.exe.121.obj - 5 error(s), 2 warning(s)运行不通过
本回答被提问者和网友采纳