帮忙看看,哪错了(C语言)
#include<stdio.h>
#include<malloc.h>
struct soldier
{
int age;
struct soldier*next;
};
int main()
{
int age=0;
int i=0;
struct soldier*p=NULL,*head=NULL,*pass=NULL;
for(i=0;i<10;i++)
{
printf("新生注册,输入年龄:");
scanf("%d",&age);
p=(struct soldier*)malloc(sizeof(struct soldier))
if(p!=NULL)
{
p->age=age;
p->next=NULL;
if(i==0)
{
head=pass=p;
}else{
pass->next=p;
pass=p;
}
p=NULL;
}
}
while(head!=NULL)
{
printf("%d",head->age);
head=head->next;
}
}
最佳答案
#include<stdio.h>
#include<malloc.h>
struct soldier
{
int age;
struct soldier*next;
};
int main()
{
int age=0;
int i=0;
struct soldier*p=NULL,*head=NULL,*pass=NULL;
for(i=0;i<10;i++)
{
printf("新生注册,输入年龄:");
scanf("%d",&age);
p=(struct soldier*)malloc(sizeof(struct soldier));
if(p!=NULL)
{
p->age=age;
p->next=NULL;
if(i==0)
{
head=pass=p;
}else{
pass->next=p;
pass=p;
}
p=NULL;
}
}
while(head!=NULL)
{
printf("%d",head->age);
head=head->next;
}
}
其他回答
暂无其它回答!