m0_58203183 2022-05-14 18:52 采纳率: 85.7%
浏览 40
已结题

求解 creat()=creat()->next;这样不可以head=creat()head=head->next可以顺序打印出去掉creat()=creat()->next又可以打印出第一个数

#include <stdio.h>
#include <stdlib.h>
#define LEN sizeof(struct Student)

struct Student
{
int num;
float score;
struct Student *next;

}man;

struct Student *creat(void)
{
struct Student *p1,*p2,head;
int n=0,i=0;
head=NULL;
p1=p2=(struct Student
)malloc(100);
printf("请输入学号:");
scanf("%d",&p1->num);
printf("请输入成绩:");
scanf("%f",&p1->score);

while(p1->num!=0)
{
    n=n+1;
    if(n==1)
    {
        head=p1;
    }
    else
    {
        p2->next=p1;
    }
    p2=p1;
    p1=(struct Student*)malloc(LEN);
    printf("请输入学号:");
    scanf("%d",&p1->num);
    printf("请输入成绩:");
    scanf("%f",&p1->score);
                
}
     p2->next=NULL;
return (head);

}

void main()
{
#if(0)
int i=0;
struct Student *head;
head=creat();

if(head!=NULL)
do
{
printf("the %d 同学的成绩: %f \n",head->num,head->score);
head=head->next;
}while(head=NULL);

#endif

struct Student *creat(void);
do
{
printf("the %d 同学的成绩: %f \n",creat()->num,creat()->score);
creat()=creat()->next;
}while(creat()!=NULL);

}

  • 写回答

2条回答 默认 最新

  • 赵4老师 2022-05-16 09:46
    关注

    create()是调用create函数,
    creat()=……;//给一个函数赋值?没有这种操作。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 5月26日
  • 已采纳回答 5月18日
  • 创建了问题 5月14日

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)