单链表实例之学生系统

单链表实例之学生系统

#include<stdio.h>
#include<stdlib.h>#define NAME_LEN 20typedef struct node {int number;char *name;struct node *next;
} node_t;node_t *g_head; int add_stu() {node_t *new, *tmp;tmp = g_head;char *name;new = (node_t *)malloc(sizeof(node_t));if (new == NULL) {printf("malloc new node fail.\n");return -1;}new->name = (char *)malloc(NAME_LEN);if (new->name == NULL) {printf("malloc new node name fail.\n");return -1;}printf("input student number:");scanf("%d", &new->number);printf("input student name:");scanf("%s", new->name);if (g_head == NULL) {g_head = new;} else {while(tmp->next != NULL) {tmp = tmp->next;}tmp->next = new;new->next = NULL;}printf("input student success.\n");return 0;
}int input_stu() 
{int choose;printf("1.input student message.\n");printf("2.back.\n");while (1) {printf("please choose:");scanf("%d", &choose);switch (choose) {case 1:add_stu();break;case 2:return -1;break;default:printf("error.\n");}printf("1.input student message.\n");printf("2.back.\n");}return 0;
}int output_stu()
{char *name;int number;node_t *new, *tmp;tmp = g_head;if (g_head == NULL) {printf("Student system is null.\n");} else {while (tmp != NULL) {printf("    %d    ", tmp->number);printf("    %s    \n", tmp->name);tmp = tmp->next;} }return 0;
}int destroy_list()
{printf("start destroy list.\n");node_t *list, *tmp;list = g_head;while (list != NULL) {tmp = list;free(tmp->name);free(tmp);list = list->next;}printf("destroy list success.\n");return 0;
}int main()
{char c;int choose;printf("Student system.\n");printf("1.input student message.\n");printf("2.output student message.\n");printf("3.exit.\n");printf("please choose:");scanf("%d", &choose);while (1) {if (choose == 3) {break;}switch (choose) {case 1:input_stu();break;case 2:output_stu();break;default:printf("error.\n");}printf("1.input student message.\n");printf("2.output student message.\n");printf("3.exit.\n");printf("please choose:");scanf("%d", &choose);}destroy_list();return 0;
}

运行结果演示:
1、复制代码到main.c文本中。
2、在linux系统下编译成可执行文件main,gcc main.c -o main。
3、编译目录下执行./main运行。
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/381838.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

公司培训文档-JavaScript[对象.属性]集锦

SCRIPT 标记 用于包含JavaScript代码. 属性 LANGUAGE 定义脚本语言 SRC 定义一个URL用以指定以.JS结尾的文件 windows对象 每个HTML文档的顶层对象. 属性 frames[] 子桢数组.每个子桢数组按源文档中定义的顺序存放. feames.length 子桢个数. self 当前窗口. parent …

uva 1252——Twenty Questions

题意&#xff1a;给定n个物品&#xff0c;每个物品用01串表示&#xff0c;表示具备与否某个特征&#xff0c;然后每次可以询问一个特征&#xff0c;问最少询问几次能够确定一个物品。 思路&#xff1a;状压Dp&#xff0c;将这些数的特征压缩成一个数&#xff0c;把询问过的和没…

[转]“UPA 中国”北京行业聚会笔录

来自:白鸦http://www.uicom.net/blog/article.asp?id409-----------“UPA 中国”北京行业聚会笔录---------------------------与会嘉宾&#xff1a;清华美院信息艺术设计系系主任&#xff1a;鲁晓波中国设计业十大杰出青年评选办公室主任&#xff1a;邢雷 清华大学工业工程系…

系统I/O小程序-文件拷贝

系统I/O小程序-文件拷贝 使用系统IO函数编写 ./syscopy src des #include <stdio.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <errno.h>/** * …

uva 10934—— Dropping water balloons

题意&#xff1a;给定K个气球&#xff0c;然后n层楼的高度&#xff0c;求确定气球的硬度&#xff08;站在多高能摔破&#xff09; 思路&#xff1a;递推。dp&#xff08;i&#xff0c;j&#xff09;表示最优&#xff0c;那么即dp&#xff08;i-1&#xff0c;j-1&#xff09;1最…

商海致富独家秘诀:微笑可以当钱花

郭俭&#xff0c;深圳凯创电子设备有限公司营销总经理。当过教师&#xff0c;坐过机关&#xff0c;最后下海了&#xff0c;来到深圳。记者到他办公室采访的时候&#xff0c;第一眼看到的&#xff0c;是他温暖而质朴的微笑。这无言的微笑&#xff0c;让人觉得站在面前的&#xf…

标准I/O小程序-文件拷贝

标准I/O小程序-文件拷贝 #include <stdio.h> #include <string.h>/** * * ./mycopy src des */ int main(int argc, char *argv[]) {FILE *des, *src;char buf[128];int ret, i, j, count;if (argc < 3) {printf("The argc is wrong!\n");retu…

uva 12105——Bigger is Better

题意&#xff1a;给定n个火柴&#xff0c;求能够摆出的最大的数。 思路&#xff1a;递推&#xff0c;dp&#xff08;i&#xff0c;j&#xff09;表示i根火柴拼出除以m余数为j的最大的数&#xff0c;然后递推用dp&#xff08;i&#xff0c;j&#xff09;*10k更新dp&#xff08;i…

[导入]Google Earth坐标集(能更看清这个世界喽!)

这里收集了一些有趣的地理坐标&#xff0c;使用方法很简单&#xff0c;先启动Google Earth&#xff0c;然后选择软件左面的部分“Fly to(飞至)”在下面的框中粘贴坐标&#xff0c;按回车即可“飞”到这个地方。珠穆朗玛峰(Mount Everest)&#xff1a;27.9782502279, 86.9221941…

fcntl函数之文件锁 F_SETLK

fcntl函数之文件锁 F_SETLK #include <stdio.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <errno.h>/** * *./myfcntl contentstruct flock {...short l_type; F_RDLCK,F_WRLCK,F_UNLCKshort l_whence; How…

uva 1625——Color Length

题意&#xff1a;给定两个长度分别为n和m 的颜色序列&#xff0c;要求按顺序合并成一个序列&#xff0c;即每次可以把开头的颜色放到新序列末尾&#xff0c;跨度l&#xff08;c&#xff09;等于最大和最小的位置之差。 思路&#xff1a;递推&#xff0c;f&#xff08;i,j&#…

刚刚注册,打声招呼先

我今天终于注册了一个属于自己的博客了。我没有用过博客&#xff0c;也很少去看别人的博客。但是登陆了计算机图形学的老师推荐的博客后&#xff0c;我觉得博客还真是个好东西。向别人展示自己的经验心得&#xff0c;与别人共享好的东西。我喜欢与人分享一切美好的东西。共享&a…

fcntl函数之文件锁 F_SETLKW

fcntl函数之文件锁 F_SETLKW F_SETLK与F_SETLKW的区别&#xff1a; F_SETLK设的锁遇到锁被其他进程占用时&#xff0c;会立刻停止进程。 F_SETLKW上锁是阻塞方式。设置的锁因为其他锁而被阻止设置时&#xff0c;该命令会等待相冲突的锁被释放。 #include <stdio.h> #inc…

uva 1331——Minimax Triangulation

题意&#xff1a;三角刨分&#xff0c;把一个m边形分解成m-2个三角形&#xff0c;求一个最大三角形最小的刨分&#xff0c;输出最小的那个三角形面积。 思路&#xff1a;递推。可能需要一点几何思维&#xff0c;d&#xff08;i&#xff0c;j&#xff09;为多边形的最优解&#…

泛型笔记

所谓泛型&#xff0c;即通过参数化类型来实现在同一份代码上操作多种数据类型。&#xff08;类型的 多态&#xff09; 是一种编程范式&#xff0c;它利用“参数化类型”讲类型抽象化&#xff0c;从而实现更为灵活的复用。 1&#xff0c;可重用行 2&#xff0c;类型安全&#xf…

进程创建fork-小代码

进程创建fork #include <sys/types.h> #include <unistd.h> pid_t fork(viod) 返回值&#xff1a;,在子进程中返回0&#xff1b;在父进程中返回大于0的进程号&#xff1b;小于0&#xff0c;出错。 fork()函数调用一次&#xff0c;返回两次&#xff0c;分别是在子进…

给有钱人办教育

今天&#xff0c;看新闻上&#xff0c;报道了&#xff0c;贷款利率又上升了。这 年头&#xff0c;什么都上涨&#xff0c;物价&#xff0c;房价&#xff0c;粮价&#xff0c;失业率也在逐年攀升&#xff0c;唯一不上涨的就是工资了&#xff0c;反而有很多很多的大学生正一次又一…

进程创建fork--文件表项继承

进程创建fork–文件表项继承 子进程继承父进程的文件描述表&#xff0c;不继承共享文件表项和iNode。 父进程创建一个子进程后&#xff0c;文件表项中的引用计数器加1变为2&#xff0c;当父进程操作close操作后&#xff0c;计数器减1&#xff0c;子进程还是可以使用文件表项&am…

论ACM ICPC_Ruins He

这段时间老是有许多新人向我问到ACM相关的问题。比如它与工作的关系&#xff0c;对我以后的工作到底有没有帮助&#xff1f;还比如说第二年的训练计划应该是什么样的&#xff1f;还有的孩子问到&#xff0c;我寒假玩儿的一个寒假&#xff0c;又该怎么办&#xff1f; 看到这些问…

查询分析器下如何备份数据库

查询分析器下如何备份数据库backupdatabasemsdb todiskd:\msdb.bakOK搞定转载于:https://www.cnblogs.com/CnKker/archive/2006/09/26/515318.html