c语言链表常错,C语言链表,哪里错了?

C4101 警告指示变量未使用。

以下是参考代码,望仔细对比,亲手练习才有益

// 使用 c11 标准编译。

#include

#include

struct student {

int num;

char name[20];

struct student *next;

};

struct student *crea(int n) {

struct student *head = NULL, *end = NULL;

for (int i = 0; i < n; i++) {

struct student *p_new =

(struct student *)malloc(sizeof(struct student)); //循环分配内存空间

if (p_new == NULL) {

printf("第%d个学生分配内存空间失败!", i + 1);

break;

}

printf("输入第%d个学生的学号:", i + 1);

scanf("%d", &p_new->num);

printf("输入第%d个学生的姓名:", i + 1);

scanf("%s", p_new->name);

p_new->next = NULL;

if (!head)

head = p_new;

if (end)

end->next = p_new;

else

end = p_new;

}

return head;

}

void print(const struct student *link) {

const struct student *curr = link;

int i = 0;

while (curr) {

printf("#%d: %s, %d\n", ++i, curr->name, curr->num);

curr = curr->next;

}

}

int main() {

struct student *link = crea(2);

print(link);

system("pause");

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值