热门

最新

红包

立Flag

投票

同城

我的

发布
m0_53493838
m0_53493838
5 年前
truem0_53493838

问什么只输出最后的数呢
#include<stdio.h>
#include<stdlib.h>
struct stu
{
int num;
struct stu *next;
};
struct stu *creat()
{
struct stu *head;
struct stu *p,*q;
q=p=(struct stu*)malloc(sizeof(struct stu));
head=NULL;
for(; q->num!=10;)
{
printf("输入\n");
scanf("%d",&p->num);
if(head==NULL)
{
head=p;
}
else
{
q->next=p;
q=p;
}
q->next=NULL;
}
return head;
}
void main()
{
struct stu *u;
u=creat();
for(; u!=NULL; u=u->next)
{
printf("%d",u->num);
}
}

CSDN App 扫码分享
分享
评论
点赞
打赏
  • 复制链接
  • 举报
下一条:
求大佬看看链表哪有问题,在线等急#include<stdio.h>#include<stdlib.h>struct stu{ int num; struct stu *next;};struct stu *creat(){ struct stu *head; struct stu *p,*q; q=p=(struct stu*)malloc(sizeof(struct stu)); head=NULL; for(; q->num!=10;) { printf("输入\n"); scanf("%d",&p->num); if(head==NULL) { head=p; } else { q->next=p; q=p; } q->next=NULL; } return head;}void main(){ struct stu *u; u=creat(); for(; u!=NULL; u=u->next) { printf("%d",u->num); }}
立即登录