dxskx 2016-09-07 09:40 采纳率: 25%
浏览 875
已结题

c语言链表问题,求助啊

#include
#include

typedef struct node
{
char name[100];
int score;
struct node *next;
}StudList;

void CreateStudent(StudList **sl)
{
int n;
StudList s, *tu;
sl = (StudList
)malloc(sizeof(StudList));
tu = sl;
printf("学生人数:");
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
s = (StudList *)malloc(sizeof(StudList));
printf("第%d个学生姓名和成绩:", i + 1);
scanf("%s-%d", s->name,&s->score);
//scanf("%d", &s->score);
tu->next = s;
tu = s;
}
tu->next = NULL;
}

void DispList(StudList *L)
{
StudList *p = L->next;
printf(" 名次 姓名 成绩\n");
int i = 1;
while (p != NULL)
{
printf(" %d\t\t", i++);
printf("%s\t\t", p->name);//有错
printf("%d\n", p->score);
p = p->next;
}
}

int main()
{
StudList *n;
printf("建立学生表\n");
CreateStudent(&n);
DispList(&n);

system("pause");
return 0;

}

大神们,我每次运行的时候都提示我注释的地方有异常,谁能帮我调一下,有赏啊,兄弟们

  • 写回答

6条回答 默认 最新

  • 编天码地 2016-09-07 11:26
    关注

    你这代码 问题很多
    DispList(&n); &n 是 StudList** 类型 而你的函数 原型 需要 StudList* 类型
    scanf("%s-%d", s->name,&s->score); 好像 并不能正确的输入
    sl = (StudList)malloc(sizeof(StudList)); 这类型 都不一致 不知道你怎么能编译不报错呢

    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示