【C语言】处女作,学籍管理_v1.0

这是一个针对初学者的C语言学籍管理系统demo,旨在提供学习参考,但存在大量goto语句,不建议模仿编程风格。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

后续我会适当更新,但不会深入更新。主要是改些BUG,这个demo适合初学者借鉴,但不要学习:用了太多goto了!

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct
{
	unsigned int *num;
	char *str;
}Buf ;
Buf buf;

struct S
{
	unsigned int xh;//学号
	char xm[20];//姓名
	unsigned int score;//成绩
	struct S *next;
}*h_sj,*p1,*p2;
#define S_size sizeof(struct S)

unsigned int jd_num=1;//节点数
unsigned int n_control=0;

struct S*sj(unsigned int x)//x作用是控制功能0初始化1正常使用
{
	if(x==0)//创建初始节点,此节点不会被使用
	{
		p1=(struct S*)malloc(S_size);
		p2=p1;h_sj=p1;
		sscanf("0 # 0","%d %s %d",&p2->xh,&p2->xm,&p2->score);
	}
	else//创建用于储存数据的节点
	{
		p1=(struct S*)malloc(S_size);
		p2->next=p1;
		p2=p1;
		p2->next=NULL;
	}
	return p2;
}

int sr()//输入函数
{
	do
	{
		if(fgets(buf.str,20,stdin)!=NULL)
		{
			break;
		}
		else
			printf("输入有误,请从新输入:");
	}
	while(1);
	if(buf.str[0]<=57&&buf.str[0]>=48)//输入的是数字
	{
		sscanf(buf.str,"%d",buf.num);
		if(*buf.num/1000!=0)
		{
			if(*buf.num/10000000000==0&&*buf.num/1000000000!=0)
				return 0;//学号
			else
				return 3;
		}
		else
			return 2;//分数
	}
	else
		return 1;//姓名
}
void lr()
{
	static struct S *temp1=NULL;//用于储存以学号区分的节点
	while(1)
	{	
		printf("请输入学号:");
xuehao:{
		   if(sr()==0)
		{
			if(jd_num>1)//遍历链表,确定无相同学号
				{
					struct S *temp2=h_sj;//取得头指针
					while(temp2!=NULL)
					{
						if(*buf.num==temp2->xh)
						{	
							printf("该学号已存在,请重新输入:");
							goto xuehao;
						}
						temp2=temp2->next;
					}
				}
				temp1=sj(1);//创建新节点
				temp1->xh=*buf.num;//记录学号
				jd_num++;
				printf("您输入的学号是:%d\n",temp1->xh);
				goto xingming;
		}
		else
		{
			printf("数据格式不匹配,请重新输入:");
			continue;
		}
	   }//学号模块
	}
xingming:{
			 printf("请输入姓名:");
			 if(sr()==1)
			 {
				 sscanf(buf.str,"%s",&temp1->xm);
				 printf("您输入的姓名是:%s\n",temp1->xm);
				 goto chengji;
			 }
			 else
			 {
				 printf("数据格式不匹配,请重新输入:");
				 goto xingming;
			 }
		 }
chengji:{
			printf("请输入成绩:");
			if(sr()==2)
			{
				temp1->score=*buf.num;
				printf("您输入的分数是:%d\n",temp1->score);
			}
			else
			{
				 printf("数据格式不匹配,请重新输入:");
				 goto chengji;
			}
		}
}


void cxxg()
{
	struct S *temp3=h_sj->next;
	struct S *temp4=h_sj;//为修改用
	printf("您共有%d条记录.\n",jd_num-1);
	if(jd_num-1==0){printf("记录为空,无法提供查询服务.\n");return;}
	printf("选择功能(0查询2修改):");
	n_control=getchar();
	getchar();
	if(n_control==50)//修改
	{
		goto xiugai1;
	}
	printf("选择查询类型(0全部输出1输入学号定位输出该条):");
	if(getchar()==48)//ASCII码中数字'0'=48;'9'=57
	{
		getchar();
		while(temp3!=NULL)
		{
			printf("学号:%d\t姓名:%s\t成绩%d\n",temp3->xh,temp3->xm,temp3->score);
			temp3=temp3->next;
		}
		return;
	}
	else//输入学号输出该条
	{
		getchar();
xiugai1: printf("请输入学号:");		
xuehao:{		
		   if(sr()==0)//学号
		{
			while(1)
			{
				if(temp3->xh==*buf.num)
				{
					printf("学号:%d\t姓名:%s\t成绩%d\n",temp3->xh,temp3->xm,temp3->score);
					if(n_control==50){goto xiugai2;}
					printf("查询完毕\n");
					return;
				}
				temp4=temp3;
				temp3=temp3->next;
				if(temp3==NULL)
				{
					printf("查无此人\n");
					return;
				}
			}
		}//以学号参考查询完毕
		else
		{
			 printf("参数格式不匹配,请重新输入:");
			 goto xuehao;
		}
	   }//学号模块结束
	}//查询结束
xiugai2:{
			printf("请选择修改类型(0删除其它键修改)");
			if(getchar()==48)
			{
				getchar();
				temp4->next=temp3->next;
				temp3->next=NULL;
				free(temp3);
				temp3=NULL;
				jd_num--;
				return;
			}

			printf("请输入新的学号:");
xg_xh:		if(sr()==0)
			{
				temp3->xh=*buf.num;
				printf("您输入的学号是:%d\n",temp3->xh);
			}
			else
			{
				 printf("参数不正确,请重新输入:");
				 goto xg_xh;
			}

			printf("请输入新的姓名:");
xg_xm:		if(sr()==1)
			{
				sscanf(buf.str,"%s",temp3->xm);
				printf("您输入的姓名是:%s\n",temp3->xm);
			}
			else
			{
				 printf("参数不正确,请重新输入:");
				 goto xg_xm;
			}

			printf("请输入新的成绩:");
xg_cg:		if(sr()==2)
			{
				temp3->score=*buf.num;
				printf("您输入的分数是:%d\n",temp3->xh);
			}
			else
			{
				 printf("参数不正确,请重新输入:");
				 goto xg_cg;
			}
		}
}
void main()
{
	int i;
	buf.num=(unsigned int*)malloc(20*sizeof(unsigned int));
	buf.str=(char*)malloc(20*sizeof(char));//分配内存空间
	sj(0);
	printf("*************************\n");
	printf("欢迎测试本程序,嘿嘿\n");
	printf("*************************\n");
w0:	printf("录数据服务请按1;\n查询服务请按2;\n修改服务请也按2;\n退出服务请右上角;\n");
	i=getchar();
	getchar();
	switch(i)
	{
		case 49:goto w1;break;
		case 50:goto w2;break;
		default:{
			printf("你怎么猜到的,这里就是退出服务\n");
			printf("请按任意键退出");
			free(buf.num);
			free(buf.str);
			getchar();exit(1);
				}
	}
w1: {
		while(1)
		{
			lr();
			printf("如需退出录入服务请按1继续请按其它键\n");
			if(getchar()==49)break;
			else getchar();
		}
		getchar();
		goto w0;
	}
w2: {
		while(1)
		{
			cxxg();
			printf("如需退出录入服务请按1继续请按其它键\n");
			if(getchar()==49)break;
			else getchar();
		}
		getchar();
		goto w0;
	}
}




想卖个小关子可是源代码给我泄了密委屈

就这样吧。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值