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 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退