首页 > 其他分享 >(C语言)我的第一个项目:命令行窗口下的学生成绩管理系统

(C语言)我的第一个项目:命令行窗口下的学生成绩管理系统

时间:2023-12-21 20:47:11浏览次数:39  
标签:&& 管理系统 int C语言 命令行 printf 033 getchar op

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
//行和列常量
#define ROW 20
#define COL 83
typedef struct student {
	char id[14];
	char name[21];
	double chinese;
	double math;
	double english;
	double sum;
} student;
int fileRead(student** ppheadStu);
int fileWrite(student* pheadStu, int num);
char getOper();
void printLine(student stu);
char printPage(student* pcurrStu, int remain, int sum, int index);
double getScore(char* pdescribe);
char processWASD(char op, student** ppcurrStu, int* premain, int sum, int* pindex);
void sort(student* pheadStu, int n, char sortAcc, char sortOp);
void processSort(char* psortOp, char* psortAco);
char processSearch(student* pheadStu, int sum, student** ppcurrStu, int* premain, int* pindex);
char processNewBuildStu(student** ppheadStu, int* psum, int* premain, int* pindex, student** ppcurrStu);
char processDeleteStu(student** ppheadStu, int* psum, int* premain, int* pindex, student** ppcurrStu);
char processChangeStu(int* psum, int* premain, int* pindex, student** ppcurrStu);
int main() {
	student* pheadStu = NULL;
	int sum = 0;
	if((sum = fileRead(&pheadStu))==-1){
		perror("main,fileRead,读取文件失败");
		return -1;
	}
	student* pcurrStu = pheadStu;
	int remain = sum,index = 1;
	char op = printPage(pcurrStu, remain, sum,index);//stu应该是值传递,不能被修改
	while (op != 'q' && op != 'Q') {
		if (op == 'l' || op == 'L') {
			char sortOp, sortAcc;
			processSort(&sortAcc, &sortOp);
			sort(pheadStu, sum, sortAcc, sortOp);
			op = printPage(pcurrStu, remain, sum, index);
		}
		else if (op == 'd' || op == 'D' || op == 'a' || op == 'A' || op == 'w' 
			|| op == 'W' || op == 's' || op == 'S') {
			op = processWASD(op, &pcurrStu, &remain, sum, &index);
		}
		else if (op == 'k' || op=='K') {
			if (processSearch(pheadStu, sum, &pcurrStu, &remain, &index)) {
				op = printPage(pcurrStu, remain, sum, index);
			}
			else {
				
			}
		}
		else if (op == 'g' || op == 'G') {
			op = processNewBuildStu(&pheadStu, &sum,&remain,&index,&pcurrStu);
		}
		else if (op == 'j' || op == 'J') {
			op = processChangeStu(&sum, &remain, &index, &pcurrStu);
		}
		else if (op == 'h' || op == 'H') {
			op = processDeleteStu(&pheadStu, &sum, &remain, &index, &pcurrStu);
		}
	}
	if(fileWrite(pheadStu,sum)==-1){
		perror("main,fileWrite,写入文件失败");
		return -1;
	}
	printf("\033[1;40;31m已退出\033[0m");

	return 0;
}
int fileRead(student** ppheadStu) {
	FILE* fp = fopen("./students.txt", "r+");
	if (fp == NULL) {
		perror("fileRead,fopen,文件打开失败");
		fclose(fp);
		return -1;
	}
	int num;
	if (fread(&num, sizeof(int), 1, fp) == 0) {
		num = 0;
		rewind(fp);
		fwrite(0, sizeof(int), 1, fp);
		fclose(fp);
		return 0;
	}
	(*ppheadStu) = (student*)malloc(sizeof(student) * num);
	if ((fread((*ppheadStu), sizeof(student), num, fp)) != num) {
		perror("fileRead,fread,读取学生信息失败");
		fclose(fp);
		return -1;
	}
	fclose(fp);
	return num;
}
int fileWrite(student* pheadStu, int num) {
	FILE* fp = fopen("./students.txt", "w");
	if (fp == NULL) {
		perror("fileWrite,fopen,打开文件失败");
		fclose(fp);
		return -1;
	}
	if (fwrite(&num, sizeof(int), 1, fp) != 1) {
		perror("fileWrite,fwrite,写入学生人数失败");
		fclose(fp);
		return -1;
	}
	if (fwrite(pheadStu, sizeof(student), num, fp) != num) {
		perror("fileWrite,fwrite,写入学生信息失败");
		fclose(fp);
		return -1;
	}
	free(pheadStu);
	fclose(fp);
	return 0;
}
char printPage(student* pcurrStu, int remain, int sum, int index) {//0<= n <=50
	char oper;
	//2 2 1 1 1 1
	printf("\033[240A\r\033[0;47;30m  |%-15s|%-20s|%-10s|%-10s|%-10s|%-10s\033[0m\n",
		"学号", "姓名", "语文", "数学", "英语", "总分");
	for (int i = 0; i < (remain > ROW ? ROW : remain); i++) {
		if (i == (index - 1)) {
			printf("\033[0;40;37m%02d\033[0m", i + 1);
		}
		else {
			printf("\033[0;47;30m%02d\033[0m", i + 1);
		}
		printLine(pcurrStu[i]);
	}
	if (remain < ROW) {
		for (int i = 1; i <= ROW - remain; i++) {
			for (int j = 1; j <= COL; j++) {
				printf("\033[0;47;30m \033[0m");
			}
			printf("\n");
		}
	}
	//指令表宽度为54个字符,,printf("\033[0;47;30m\033[0m");返回值为14
	int lenOfFooter = printf("\033[0;47;30m第 %d / %d 页\033[0m",
		(sum - remain) / ROW + 1, sum / ROW + (sum % ROW == 0 ? 0 : 1));
	lenOfFooter -= 14;
	printf("\033[0;47;30m|\033[0m\033[1;47;31m上一页:a/A\033[0m");
	printf("\033[0;47;30m|\033[0m\033[1;47;31m下一页:d/D\033[0m");
	printf("\033[0;47;30m|\033[0m\033[1;47;31m上一个:w/W\033[0m");
	printf("\033[0;47;30m|\033[0m\033[1;47;31m下一个:s/S\033[0m");
	printf("\033[0;47;30m|\033[0m\033[1;47;31m退出:q/Q\033[0m\033[0;47;30m|\033[0m");
	for (int i = 54 + lenOfFooter + 1; i <= COL; i++) {
		printf("\033[0;47;30m \033[0m");
	}
	printf("\n");
	for (int i = 1; i <= lenOfFooter; i++) {
		printf("\033[0;47;30m \033[0m");
	}
	printf("\033[0;47;30m|\033[0m\033[1;47;31m新建:g/G  \033[0m");
	printf("\033[0;47;30m|\033[0m\033[1;47;31m删除:h/H  \033[0m");
	printf("\033[0;47;30m|\033[0m\033[1;47;31m修改:j/J  \033[0m");
	printf("\033[0;47;30m|\033[0m\033[1;47;31m查找:k/K  \033[0m");
	printf("\033[0;47;30m|\033[0m\033[1;47;31m排序:l/L\033[0m\033[0;47;30m|\033[0m");
	for (int i = 54 + lenOfFooter + 1; i <= COL; i++) {
		printf("\033[0;47;30m \033[0m");
	}
	printf("\n");
	printf("\033[K输入操作指令:");
	oper = getOper();
	return oper;
}
void printLine(student stu) {//COL - 2个字符
	printf("\033[0;47;30m|%-15s|%-20s|%-10.2lf|%-10.2lf|%-10.2lf|%-10.2lf\033[0m\n", 
		stu.id, stu.name, stu.chinese, stu.math, stu.english, stu.sum);
}
double getScore(char* pdescribe) {
	double result;
	char score[7];
	score[6] = '\0';
reset:;
	result = 0;
	int i = 0;
	int dot = 6, isDot = 0;
	while ((score[i] = getchar()) != '\n' && i <= 5) {
		if ((score[i] < '0' || score[i]>'9') && score[i] != '.') {
			printf("\033[1A\033[K输入错误,请重新输入%s成绩(000.00~100.00):", pdescribe);
			while (getchar() != '\n') {
				continue;
			}
			goto reset;
		}
		if (score[i] == '.') {
			if (isDot) {
				printf("\033[1A\033[K输入错误,请重新输入%s成绩(000.00~100.00):", pdescribe);
				while (getchar() != '\n') {
					continue;
				}
				goto reset;
			}
			else {//isDot == 0
				isDot = 1;
			}
			dot = i;
		}
		i++;
	}
	if (score[0] == '\n') {
		printf("\033[1A\033[K输入错误,请重新输入%s成绩(000.00~100.00):", pdescribe);
		goto reset;
	}
	if (score[i] != '\n') {
		printf("\033[1A\033[K输入数据太长,请重新输入%s成绩(000.00~100.00):", pdescribe);
		while (getchar() != '\n') {
			continue;
		}
		goto reset;
	}
	else {//score[i]=='\n'
		if (dot == 6) {
			dot = i;
		}
	}
	score[i] = '\0';
	for (int i = 0; i <= 5; i++) {
		if ((score[i] < '0' || score[i]>'9') && score[i] != '.') {
			break;
		}
		if (i < dot) {
			result += (score[i] - '0') * pow(10.0, (dot - i - 1.0));
		}
		else if (i > dot) {
			result += (double)(score[i] - '0') / pow(10.0, (i - dot));
		}
	}
	if (result < 0.0 || result>100.0) {
		printf("\033[1A\033[K输入数据超过范围,请重新输入%s成绩(000.00~100.00):", pdescribe);
		goto reset;
	}
	return result;
}
char getOper() {
	char c;
	c = getchar();
	if (c != '\n') {
		while (getchar() != '\n') {
			continue;
		}
	}
	while (c != 'd' && c != 'D' && c != 'a' && c != 'A' && c != 'w' && c != 'W' && c != 's' 
		&& c != 'S'&& c != 'q' && c != 'Q' && c != 'g' && c != 'G' && c != 'h' && c != 'H' 
		&& c != 'j'&& c != 'J' && c != 'k' && c != 'K' && c != 'l' && c != 'L') {
		printf("\033[1A\033[K输入错误,请重新输入操作指令:");
		c = getchar();
		if (c != '\n') {
			while (getchar() != '\n') {
				continue;
			}
		}
	}
	return c;
}
char processWASD(char op, student** ppcurrStu, int* premain, int sum,int* pindex) {
	switch (op) {
		case 'd':
		case 'D':
			if ((*premain) <= ROW) {
				printf("\033[1A\033[K已经是最后一页了,重新输入操作指令:");
				op = getOper();
				while(op == 'd' || op == 'D') {
					printf("\033[1A\033[K已经是最后一页了,重新输入操作指令:");
					op = getOper();
				}
				return op;
			}
			(*ppcurrStu)+=ROW;
			(*premain) -=ROW;
			if ((*pindex) > (*premain)) {
				(*pindex) = (*premain);
			}
			op = printPage((*ppcurrStu), (*premain), sum,(*pindex));
			return op;
			break;
		case 'a':
		case 'A':
			if ((*premain) == sum) {
				printf("\033[1A\033[K已经是第一页了,请重新输入操作指令:");
				op = getOper();
				while (op == 'a' || op == 'A') {
					printf("\033[1A\033[K已经是第一页了,请重新输入操作指令:");
					op = getOper();
				}
				return op;
			}
			(*ppcurrStu) -= ROW;
			(*premain) += ROW;
			op = printPage((*ppcurrStu), (*premain), sum,(*pindex));
			return op;
			break;
		case 'w':
		case 'W':
			if ((*pindex) == 1) {
				printf("\033[1A\033[K已经是第一个了,请重新输入操作指令:");
				op = getOper();
				while (op == 'w' || op == 'W') {
					printf("\033[1A\033[K已经是第一个了,请重新输入操作指令:");
					op = getOper();
				}
				return op;
			}
			(*pindex)--;
			op = printPage((*ppcurrStu), (*premain), sum,(*pindex));
			break;
		case 's':
		case 'S':
			if ((*pindex) == ROW || (*pindex)==(*premain) ) {
				while (op == 's' || op == 'S') {
					printf("\033[1A\033[K已经是最后一个了,请重新输入操作指令:");
					op = getOper();
				}
				return op;
			}
			(*pindex)++;
			op = printPage((*ppcurrStu), (*premain), sum, (*pindex));
			return op;
			break;
		/*default:
			op = getOper();
			return op;
			break;*/
	}
}
void sort(student* pheadStu, int n, char sortAcc,char sortOp) {//op==1,由大到小
	for (int i = 0; i < n; i++) {
		for (int j = i; j > 0; j--) {
			double current, next;
			switch (sortAcc) {
				case 'l':
				case 'L':
					current = pheadStu[j].sum;
					next = pheadStu[j - 1].sum;
					break;
				case 'h':
				case 'H':
					current = pheadStu[j].chinese;
					next = pheadStu[j - 1].chinese;
					break;
				case 'j':
				case 'J':
					current = pheadStu[j].math;
					next = pheadStu[j - 1].math;
					break;
				case 'k':
				case 'K':
					current = pheadStu[j].english;
					next = pheadStu[j - 1].english;
					break;
				case 'g':
				case 'G': {
					int compare = strcmp(pheadStu[j].id, pheadStu[j - 1].id);
					if (compare < 0) {
						current = 1.0;
						next = 2.0;
					}
					else if (compare > 0) {
						current = 2.0;
						next = 1.0;
					}
					else {
						current = 1.0;
						next = 1.0;
					}
					break;
				}
			}
			if (current > next) {
				if (sortOp =='w'|| sortOp =='W') {
					student temp = pheadStu[j];
					pheadStu[j] = pheadStu[j - 1];
					pheadStu[j - 1] = temp;
				}
				else {
					break;
				}
				
			}
			else if(current < next){
				if (sortOp == 'w'|| sortOp =='W') {
					break;
				}
				else {
					student temp = pheadStu[j];
					pheadStu[j] = pheadStu[j - 1];
					pheadStu[j - 1] = temp;
				}
			}
			else if (current == next) {
				break;
			}
		}
	}
}
void processSort(char* psortAcc,char* psortOp) {
	printf("\033[1A\033[K输入排序依据(学号:g/G,语文:h/H,数学:j/J,英语:k/K,总分:l/L): ");
	(*psortAcc) = getchar();
	if ((*psortAcc) != '\n') {
		while (getchar() != '\n') {
			continue;
		}
	}
	while ((*psortAcc) != 'g' && (*psortAcc) != 'G' && (*psortAcc) != 'h' && (*psortAcc) != 'H' 
		&& (*psortAcc) != 'j' && (*psortAcc) != 'J' &&(*psortAcc) != 'k' && (*psortAcc) != 'K'
		&& (*psortAcc) != 'l' && (*psortAcc) != 'L') {
		printf("\033[1A\033[K输入错误,请重新输入排序依据(学号:g/G,语文:h/H,数学:j/J,英语:k/K,总分:l/L):");
		(*psortAcc) = getchar();
		if ((*psortAcc) != '\n') {
			while (getchar() != '\n') {
				continue;
			}
		}
	}
	printf("\033[1A\033[K输入排序方式(由小到大:s,由大到小:w):");
	(*psortOp) = getchar();
	if ((*psortOp != '\n')) {
		while (getchar() != '\n') {
			continue;
		}
	}
	while ((*psortOp) != 's' && (*psortOp) != 'S' && (*psortOp) != 'w' && (*psortOp) != 'W') {
		printf("\033[1A\033[K输入错误,请重新输入排序方式(由小到大:s,由大到小:w):");
		(*psortOp) = getchar();
		if ((*psortOp) != '\n') {
			while (getchar() != '\n') {
				continue;
			}
		}
	}
}
char processSearch(student* pheadStu, int sum, student** ppcurrStu, int* premain, int* pindex) {
	printf("\033[1A\033[K输入要查找学生的学号(13位数字):\033[0m");
	char searId[14];
	searId[13] = '\0';
	reset:;
	for (int i = 0; i < 13; i++) {											
		searId[i] = getchar();
		if (searId[i] < '0' || searId[i]>'9') {
			if (searId[i] != '\n') {
				while (getchar() != '\n') {
					continue;
				}
			}
			printf("\033[1A\033[K输入错误,请重新开始输入要查找学生的学号:");
			goto reset;
		}
	}
	while (getchar() != '\n') {
		while (getchar() != '\n') {
			continue;
		}
		printf("\033[1A\033[K输入学号过长,请重新开始输入要查找学生的学号:");
		goto reset;
		continue;
	}
	for (int i = 0; i < sum; i++) {
		if (strcmp(searId, pheadStu[i].id)==0) {
			(*ppcurrStu) = pheadStu+(i-i%ROW);//i/ROW*ROW
			(*pindex) = i % ROW + 1;
			(*premain) = sum - (i - i % ROW);
			return printPage((*ppcurrStu), (*premain), sum, (*pindex));
		}
	}
	printf("\033[1A\033[K此成绩单里没有该学生,请输入操作指令:");
	return getOper();
}
char processNewBuildStu(student** ppheadStu, int* psum,int *premain,int* pindex,student **ppcurrStu) {
	student tempStu;
	tempStu.chinese = 0;
	tempStu.math = 0;
	tempStu.english = 0;

	tempStu.id[13] = '\0';
	printf("\033[1A\033[K请输入新建学生的学号(13位数字):");
resetId:;
	for (int i = 0; i < 13; i++) {
		tempStu.id[i] = getchar();
		if (tempStu.id[i] < '0' || tempStu.id[i]>'9') {
			if (tempStu.id[i] != '\n') {
				while (getchar() != '\n') {
					continue;
				}
			}
			printf("\033[1A\033[K输入错误,请重新开始输入新建学生的学号(13位数字):");
			goto resetId;
		}
	}
	if (getchar() != '\n') {
		printf("\033[1A\033[K输入学号过长,请重新开始新建学生的输入学号(13位数字):");
		while (getchar() != '\n') {
			continue;
		}
		goto resetId;
	}
	
resetName:;
	printf("\033[1A\033[K请输入新建学生的姓名(最大20个字符,一个汉字算两个字符):");
	char avoidEnter;
	while ((avoidEnter = getchar()) == '\n') {
		printf("\033[1A\033[K输入错误,请重新输入新建学生的姓名:");
		continue;
	}
	tempStu.name[0] = avoidEnter;
	int i = 1;
	while ((tempStu.name[i] = getchar()) != '\n' && i <= 19) {
		i++;
		continue;
	}
	if (tempStu.name[i] != '\n') {
		printf("\033[1A\033[K输入姓名过长,请重新输入新建学生的姓名(最大20个字符,一个汉字算两个字符):");
		while (getchar() != '\n') {
			continue;
		}
		goto resetName;
	}
	tempStu.name[i] = '\0';

	printf("\033[1A\033[K请输入新建学生的语文成绩(000.00~100.00):");
	tempStu.chinese = getScore("新建学生的语文");
	printf("\033[1A\033[K请输入新建学生的数学成绩(000.00~100.00):");
	tempStu.math = getScore("新建学生的数学");
	printf("\033[1A\033[K请输入新建学生的英语成绩(000.00~100.00):");
	tempStu.english = getScore("新建学生的英语");

	tempStu.sum = tempStu.chinese + tempStu.math + tempStu.english;

	//新建空间
	(*psum)++;
	student* pnewHeadStu = (student*)malloc(sizeof(student) * (*psum));
	for (int i = 0; i <= (*psum) - 2; i++) {
		pnewHeadStu[i] = (*ppheadStu)[i];
	}
	pnewHeadStu[(*psum) - 1] = tempStu;
	free(*ppheadStu);
	(*ppheadStu) = pnewHeadStu;

	//修改页面显示到新建学生数据
	(*ppcurrStu) = (*ppheadStu) + ((*psum) - 1) / ROW * ROW;
	(*premain) = (*psum) - ((*psum) - 1) / ROW * ROW;
	(*pindex) = ((*psum) - 1) % ROW + 1;
	char op = printPage((*ppcurrStu), *premain, *psum, *pindex);
	return op;
}
char processChangeStu(int* psum, int* premain, int* pindex, student** ppcurrStu) {
	student tempStu;
	char isSkip;

	printf("\033[1A\033[K输入要修改的学生所在行的序号(1~%d):", ROW);
resetIndex:;
	int realNumber = 0;
	char charNumber;
	while ((charNumber = getchar()) != '\n') {
		if (charNumber < '0' || charNumber>'9') {
			printf("\033[1A\033[K输入错误,请重新输入要修改的学生所在行的序号(1~%d):", ROW);
			while (getchar() != '\n') {
				continue;
			}
			goto resetIndex;
		}
		realNumber *= 10;
		realNumber += charNumber - '0';
		if (realNumber > 20) {
			printf("\033[1A\033[K输入序号超过范围,请请重新输入要修改的学生所在行的序号(1~%d):", ROW);
			while (getchar() != '\n') {
				continue;
			}
			goto resetIndex;
		}
	}
	if (realNumber <= 0) {
		printf("\033[1A\033[K输入错误,请重新输入要修改的学生所在行的序号(1~%d):", ROW);
		goto resetIndex;
	}
	(*pindex) = realNumber;

	tempStu = (*ppcurrStu)[(*pindex) - 1];

	//Id========================================================
	tempStu.id[13] = '\0';
	printf("\033[1A\033[K是否修改学号(是:e/E,否:q/Q):");
	while ((isSkip=getchar()) != 'q' && isSkip != 'Q' && isSkip != 'e' && isSkip != 'E') {
		if (isSkip != '\n') {
			while (getchar() != '\n') {
				continue;
			}
		}
		printf("\033[1A\033[K输入错误,请重新输入,是否修改学号(是:e/E,否:q/Q):");
	}
	while (getchar() != '\n') {
		continue;
	}

	if (isSkip == 'e' || isSkip == 'E') {
		printf("\033[1A\033[K请输入修改后的学号(13位数字):");
	resetId:;
		for (int i = 0; i < 13; i++) {
			tempStu.id[i] = getchar();
			if (tempStu.id[i] < '0' || tempStu.id[i]>'9') {
				if (tempStu.id[i] != '\n') {
					while (getchar() != '\n') {
						continue;
					}
				}
				printf("\033[1A\033[K输入错误,请重新开始输入修改后的学号(13位数字):");
				goto resetId;
			}
		}
		if (getchar() != '\n') {
			printf("\033[1A\033[K输入学号过长,请重新开始输入修改后的学号(13位数字):");
			while (getchar() != '\n') {
				continue;
			}
			goto resetId;
		}
		tempStu.id[13] = '\0';
	}

	//姓名========================================================
	printf("\033[1A\033[K是否修改姓名(是:e/E,否:q/Q):");
	while ((isSkip = getchar())!='q'&&isSkip!='Q'&&isSkip!='e'&&isSkip!='E') {
		if (isSkip != '\n') {
			while (getchar() != '\n') {
				continue;
			}
		}
		printf("\033[1A\033[K输入错误,请重新输入,是否修改姓名(是:e/E,否:q/Q):");
	}
	while (getchar() != '\n') {
		continue;
	}
	if (isSkip == 'e' || isSkip == 'E') {
		printf("\033[1A\033[K请输入修改后的姓名(最大20个字符,一个汉字算两个字符):");
	resetName:;
		int i = 0;
		while ((tempStu.name[i] = getchar()) != '\n' && i <= 19) {
			i++;
		}
		if (tempStu.name[i] != '\n') {
			printf("\033[1A\033[K输入姓名过长,请重新输入修改后的姓名(最大20个字符,一个汉字算两个字符):");
			while (getchar() != '\n') {
				continue;
			}
			goto resetName;
		}
		tempStu.name[i] = '\0';
	}

	//成绩==============================================================
	
	printf("\033[1A\033[K是否修改语文成绩(是:e/E,否:q/Q):");
	while ((isSkip = getchar())!='q'&&isSkip!='Q'&&isSkip!='e'&&isSkip!='E') {
		if (isSkip != '\n') {
			while (getchar() != '\n') {
				continue;
			}
		}
		printf("\033[1A\033[K输入错误,请重新输入,是否修改语文成绩(是:e/E,否:q/Q):");
	}
	while (getchar() != '\n') {
		continue;
	}
	if (isSkip == 'e' || isSkip == 'E') {
		printf("\033[1A\033[K请输入修改后的语文成绩(000.00~100.00):");
		tempStu.chinese = getScore("修改后的语文");
	}

	printf("\033[1A\033[K是否修改数学成绩(是:e/E,否:q/Q):");
	while ((isSkip = getchar()) != 'q' && isSkip != 'Q' && isSkip != 'e' && isSkip != 'E') {
		if (isSkip != '\n') {
			while (getchar() != '\n') {
				continue;
			}
		}
		printf("\033[1A\033[K输入错误,请重新输入,是否修改数学成绩(是:e/E,否:q/Q):");
	}
	while (getchar() != '\n') {
		continue;
	}
	if (isSkip == 'e' || isSkip == 'E') {
		printf("\033[1A\033[K请输入修改后的数学成绩(000.00~100.00):");
		tempStu.math = getScore("修改后的数学");
	}

	printf("\033[1A\033[K是否修改英语成绩(是:e/E,否:q/Q):");
	while ((isSkip = getchar()) != 'q' && isSkip != 'Q' && isSkip != 'e' && isSkip != 'E') {
		if (isSkip != '\n') {
			while (getchar() != '\n') {
				continue;
			}
		}
		printf("\033[1A\033[K输入错误,请重新输入,是否修改英语成绩(是:e/E,否:q/Q):");
	}
	while (getchar() != '\n') {
		continue;
	}
	if (isSkip == 'e' || isSkip == 'E') {
		printf("\033[1A\033[K请输入修改后的英语成绩(000.00~100.00):");
		tempStu.english = getScore("修改后的英语");
	}
	tempStu.sum = tempStu.chinese + tempStu.math + tempStu.english;

	(*ppcurrStu)[(*pindex) - 1] = tempStu;

	char op = printPage(*ppcurrStu, *premain, *psum, *pindex);

	return op;
		
}
char processDeleteStu(student** ppheadStu, int* psum, int* premain, int* pindex, student** ppcurrStu) {
	printf("\033[1A\033[K输入要删除的学生成绩所在行的序号(1~%d):", ROW);
reset:;
	int realNumber = 0;
	char charNumber;
	while ((charNumber = getchar()) != '\n') {
		if (charNumber < '0' || charNumber>'9') {
			printf("\033[1A\033[K输入错误,请重新输入要删除的学生成绩所在行的序号(1~%d):", ROW);
			while (getchar() != '\n') {
				continue;
			}
			goto reset;
		}
		realNumber *= 10;
		realNumber += charNumber - '0';
		if (realNumber > ROW) {
			printf("\033[1A\033[K输入序号超过范围,请重新输入要删除的学生成绩所在行的序号(1~%d):", ROW);
			while (getchar() != '\n') {
				continue;
			}
			goto reset;
		}
	}
	if (realNumber <= 0) {
		printf("\033[1A\033[K输入错误,请重新输入要删除的学生成绩所在行的序号(1~%d):", ROW);
		goto reset;
	}
	if ((*premain) < realNumber) {
		printf("\033[1A\033[K该序号所在行没有学生数据,请重新输入要删除的学生数据所在行的序号(1~%d):", ROW);
		goto reset;
	}
	for (int i = 0; i < (*premain) - realNumber; i++) {
		(*ppcurrStu)[realNumber - 1 + i] = (*ppcurrStu)[realNumber - 1 + i + 1];
	}
	(*psum)--;
	(*premain)--;
	
	student* ptempHeadStu = (student*)malloc(sizeof(student) * (*psum));
	if (ptempHeadStu == NULL) {
		perror("processDeleteStu,malloc,开辟空间错误");
		return 'q';
	}
	for (int i = 0; i < (*psum); i++) {
		ptempHeadStu[i] = (*ppheadStu)[i];
	}
	free(*ppheadStu);
	(*ppheadStu) = ptempHeadStu;
	(*ppcurrStu) = (*ppheadStu) + ((*psum) - (*premain));
	if ((*premain) == 0) {
		(*ppcurrStu) -= ROW;
		(*premain) = ROW;
		(*pindex) = ROW;
	}
	return printPage((*ppcurrStu), (*premain), (*psum), (*pindex));
}



标签:&&,管理系统,int,C语言,命令行,printf,033,getchar,op
From: https://www.cnblogs.com/l25428455/p/17920070.html

相关文章

  • 数字化医学影像系统源码,采用C语言开发,支持MPR、CPR、MIP、SSD、VR、VE三维图像处理
    PACS系统是医院影像科室中应用的一种系统,主要用于获取、传输、存档和处理医学影像。它通过各种接口,如模拟、DICOM和网络,以数字化的方式将各种医学影像,如核磁共振、CT扫描、超声波等保存起来,并在需要时能够快速调取和使用。PACS系统还提供了辅助诊断和管理功能,可以在不同的影像设备......
  • 不是IAM身份和访问管理系统用不起,而是统一身份中台更有性价比
    单点登录(SingleSign-On,简称SSO)是一种常见的企业身份验证方案,用户通过一次登录即可访问多个应用系统。然而,如果企业没有完成『身份整合与统一』这一步,那么这个单点登录方案就不能算是理想的解决方案。在探讨这个问题之前,我们需要先理解统一身份的概念。统一身份是指将企业中所有用......
  • 2023最新高级难度C语言面试题,包含答案。刷题必备!记录一下。
    好记性不如烂笔头内容来自面试宝典-高级难度C语言面试题合集问:在C语言中,如何使用结构体进行面向对象编程?在C语言中,虽然没有像C++或Java那样的类和对象概念,但可以通过结构体、函数指针和其他技术来模拟面向对象编程的某些特性。以下是一些使用结构体进行面向对象编程的关......
  • 2023最新中级难度C语言面试题,包含答案。刷题必备!记录一下。
    好记性不如烂笔头内容来自面试宝典-中级难度C语言面试题合集问:在C语言中,如何使用指针访问数组的各个元素?在C语言中,数组名实际上是一个指向数组第一个元素的指针。因此,我们可以使用指针算术来访问数组的各个元素。下面是一个示例代码,演示如何使用指针访问数组的各个元素:......
  • cmd命令行设置 windows 设置环境变量
    设置用户级别的环境变量::设置新参数JAVA_HOME1setxJAVA_HOME1"c:\test";exit;echo"%JAVA_HOME1%";::追加参数内容JAVA_HOME1setxJAVA_HOME1"%JAVA_HOME1%;c:\test2\;";exit;echo"%JAVA_HOME1%";::追加到Pathsetxpath"%pat......
  • 7z 命令行压缩解压详解-中文版
    1)简介7z,全称7-Zip,是一款开源软件。是目前公认的压缩比例最大的压缩解压软件。主页:http://www.7-zip.org/中文主页:http://7z.sparanoid.com/命令行版本下载:http://7z.sparanoid.com/download.htmlWindows去官网下载安装包安装linux使用命令安装:sudoaptinstallp7zip-full......
  • 2023最新初级难度C语言面试题,包含答案。刷题必备!记录一下。
    好记性不如烂笔头内容来自面试宝典-初级难度C语言面试题合集问:C语言中,main函数的返回值类型是什么?在C语言中,main函数的返回值类型是int。这是因为main函数是程序的入口点,它返回一个整数值给操作系统,以表示程序的退出状态。通常,如果程序正常退出,main函数返回0;如果程序出现......
  • 1842_emacs使用company-irony实现C语言的自动补全
    Grey全部学习内容汇总:GitHub-GreyZhang/editors_skills:SummaryforsomecommoneditorskillsIused.1842_emacs使用company-irony实现c语言的自动补全irony-mode是一个自动补全的实现方案,配合company集成之后效果非常好。简单调试完了之后,基本上能够确定这是我这么多年来使......
  • 1835_GCC中C语言typeof的使用
    Grey全部学习内容汇总:GitHub-GreyZhang/c_basic:littlebitsofc.1835_GCC中C语言typeof的使用typeof是C语言中对数据类型的一种引用方法,目前看到的信息来看,并不是标准C中提供或者要求的内容。这个功能,其实是编译器提供的一种便捷的操作模式。而我看的资料中,这个功能在gcc中是......
  • 深入c语言中的数组
    在C语言中,数组是一种非常重要的数据结构,它可以用来存储一系列相同类型的数据。数组在C语言中被广泛应用于各种算法和数据处理中,因此了解和掌握数组的使用是非常重要的。数组的声明和初始化在C语言中,数组的声明和初始化非常简单。我们可以通过以下语法来声明和初始化一个数组:intarr......