帮忙看看,哪错了(C语言)

原问题:帮忙看看,哪错了(C语言)
分类:编程开发 > 最后更新时间:【2017-07-28 18:31:27】
问题补充:

#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;

}

}

最佳答案由网友  360U2828515910  提供
公告: 为响应国家净网行动,部分内容已经删除,感谢网友理解。
11

分享到:

其他回答

暂无其它回答!

    推荐