c语言用链表添加学生信息

c语言用链表添加学生信息,第1张

#include <stdio.h>

#include <string.h>

# include "stdlib.h"

#define LEN sizeof(struct stu)

struct stu

{

long num

char name[20]

char sex 

int age

char addr[30]

struct stu *next

}

int main()

{

int n

struct stu *head

struct stu *p1,*p2

head=(struct stu*)malloc (LEN)

head->next=NULL

p1=head

p2=(struct stu*)malloc (LEN)

p2->next=NULL

printf("学号\t姓名\t性别\t年龄\t住址\n")

scanf("%ld,\t%s,\t%c,\t%d,\t%s",&p2->num,&p2->name,&p2->sex,&p2->age,&p2->addr)

while(p2->num!=0)

{

p1->next=p2

p1=p2

fflush(stdin)

p2=(struct stu*)malloc (LEN)

printf("学号\t姓名\t性别\t年龄\t住址\n")

scanf("%ld,%s,%c,%d,%s",&p2->num,&p2->name,&p2->sex,&p2->age,&p2->addr)

}

}

纯手打,希望采纳。

构造一个关于学生信息的数据类型

如:

struct studengt_type

{

int number //学号

char *name//姓名

char sex//性别

int score// 入学成绩

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11607487.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存