当前位置:网站首页>C student management system head to add a student node
C student management system head to add a student node
2022-08-05 02:18:00 【joker_0030】
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
//学生节点.
typedef struct _STU
{
char arrStuNum[10];
char arrStuName[10];
int iStuScore;
struct _STU* pNext;//指向下一个节点.
}STUNODE;
//Declare the head and tail of the linked list.
STUNODE* g_pHead = NULL;
STUNODE* g_pEnd = NULL;
//Add information to the header of the linked list.
void AddStuMSGToLinkHead(char* arrStuNum[10], char arrStuName[10], int iStuScore);
int main()
{
int nOrder = -1;
char arrStuNum[10] = { '\0' };
char arrStuName[10] = { '\0' };
int iStuScore = -1;
int nFlag = 1;
//显示指令.
ShowOrder();
while (nFlag)
{
printf("请输入操作指令(0for viewing instructions)\n");
scanf("%d", &nOrder);
switch (nOrder)
{
case 1://添加一个学生信息.
printf("输入学号:");
scanf("%s", arrStuNum);
printf("输入姓名:");
scanf("%s", arrStuName);
printf("输入分数:");
scanf("%d", &iStuScore);//取地址.
AddStuMSG(arrStuNum, arrStuName, iStuScore);
break;
case 10://头添加.
printf("输入学号:");
scanf("%s", arrStuNum);
printf("输入姓名:");
scanf("%s", arrStuName);
printf("输入分数:");
scanf("%d", &iStuScore);//取地址.
AddStuMSGToLinkHead(arrStuNum, arrStuName, iStuScore);
break;
case 2:
printf("请输入学生学号/姓名");
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8://打印数据(链表).
ShowStuData();
break;
case 9:
nFlag = 0;
break;
case 0:
//查看指令.
ShowOrder();
break;
default:
printf("输入的指令不对");
break;
}
}
//释放链表.
FreeLinkData();
system("pause");
return 0;
}
//Add information to the header of the linked list.
void AddStuMSGToLinkHead(char* arrStuNum[10], char arrStuName[10], int iStuScore)
{
//检测参数的合法性.
if (NULL == arrStuNum || NULL == arrStuName || iStuScore < 0)
{
printf("学生信息输入错误.\n");
return;
}
//创建一个节点.
STUNODE* pTemp = malloc(sizeof(STUNODE));
//成员赋值.
strcpy(pTemp->arrStuNum, arrStuNum);//Because the array is completely a pointer when it is passed in as a parameter.
strcpy(pTemp->arrStuName, arrStuName);//Because the array is completely a pointer when it is passed in as a parameter.
pTemp->iStuScore = iStuScore;
pTemp->pNext = NULL;
if (NULL == g_pHead || NULL == g_pEnd)
{
//链表为空.
g_pHead = pTemp;
g_pEnd = pTemp;
}
else
{
//The next point of the new node points to the head.
pTemp->pNext = g_pHead;
//向前移动一个.
g_pHead = pTemp;
}
}
边栏推荐
- Opening - Open a new .NET modern application development experience
- C语言实现简单猜数字游戏
- How to simply implement the quantization and compression of the model based on the OpenVINO POT tool
- .Net C# Console Create a window using Win32 API
- 使用SuperMap iDesktopX数据迁移工具迁移地图文档和符号
- std::string::find 返回值的坑
- C语言日记 9 if的3种语句
- 蚁剑高级模块开发
- 常见的硬件延迟
- Greenplum数据库故障分析——能对数据库base文件夹进行软连接嘛?
猜你喜欢
随机推荐
CPDA|运营人如何从负基础学会数据分析(SQL)
特殊矩阵的压缩存储
Greenplum Database Fault Analysis - Why Does gpstart -a Return Failure After Version Upgrade?
CMS website construction process
如何模拟后台API调用场景,很细!
Fragment visibility judgment
Apache DolphinScheduler新一代分布式工作流任务调度平台实战-中
进程在用户态和内核态的区别[独家解析]
MySQL学习
回顾51单片机
Greenplum Database Fault Analysis - Can a Soft Connection Be Made to the Database Base Folder?
C语言日记 9 if的3种语句
一文看懂推荐系统:召回06:双塔模型——模型结构、训练方法,召回模型是后期融合特征,排序模型是前期融合特征
".NET IoT from scratch" series
使用SuperMap iDesktopX数据迁移工具迁移地图文档和符号
Greenplum数据库故障分析——能对数据库base文件夹进行软连接嘛?
Live preview | 30 minutes started quickly!Look at credible distributed AI chain oar architectural design
网络安全与元宇宙:找出薄弱环节
[Word] #() error occurs after Word formula is exported to PDF
[Unity Entry Plan] Handling of Occlusion Problems in 2D Games & Pseudo Perspective