⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 file.c

📁 软件的名称:学生信息管理系统 软件的功能:登录功能、主菜单功能、学生信息录入功能、学生记录的排序功能、查询和删除功能、学生信息打印功能、记录保存功能、记录读取功能、分数统计报表功能和退出功能等。
💻 C
字号:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <conio.h>
#include <malloc.h>
#include <io.h>
#include "FuncDeclare.h"
#include "link.h"
#define LEN sizeof(student)
extern inforsave;
extern Sno_count;
extern student *head,*last;

//文件名验证
int CheckFileName(char str[])
{
	int len;
	int j =0;
	int i =0;
	RomoveLeftBlank(str);//去左空格
	len=strlen(str);
	if(len<=0)
		return 1;//为空
	else 
	{
		while(j<len)
		{
			if(str[j] !=46)
			{
				i++;
				if(i>8)
					return 2;//文件名大于8
				if(str[j]=='\\' || str[j]=='/' || str[j]==':'  || str[j]=='*' || str[j]=='?' || str[j]=='"' || str[j]=='<' || str[j]=='>' || str[j]=='|')
					return 3;//非法
			}
			else
				 break;
			j++;
		}
	}
	//if(str[j]!=46)
		//return 4;//文件名没后缀
	return 0;
}

//执行数据保存,0用于保存功能块
int SaveData(int xcursor,int ycursor,int flag)
{
	int re_input;
	int checkfilename;
	int chooseerr;
	char choose[1];
	char file[50];
	FILE *fp;
	student *p;
	p=head;
	if(flag==0)
	{
		CleanMenuInfo();
		SetXY(35,2);
		printf("Save Stu Data");
	}
	do
	{
		SetXY(xcursor,ycursor);
		printf("Sava File Path:");
		SetXY(1,21);
		printf("Press ESC to Quit");
		SetXY(21,ycursor);
		re_input=input(file,40);
		if(re_input==1)
			return 0;
		checkfilename=CheckFileName(file);
		if(checkfilename==1)
		{
			ShowMessge("Filename cannot be null!...enter any key to back");
			getch();
			ClearScreen(21,10,78,10);//清除前一次操作
			ClearScreen(1,19,78,20);//清除信息框内容
		}
		else if(checkfilename==2)
		{
			ShowMessge("File Length is more than 8!...enter any key to back");
			getch();
			ClearScreen(21,10,78,10);//清除前一次操作
			ClearScreen(1,19,78,20);//清除信息框内容
		}
		else if(checkfilename==3)
		{
			ShowMessge("Filename contains invalid character...enter any key to back");
			getch();
			ClearScreen(21,10,78,10);//清除前一次操作
			ClearScreen(1,19,78,20);//清除信息框内容
		}
		else
			break;
    }while(1);
	if(access(file,0)==0)
	{
		if(access(file,2)==0)
		{
			CleaseMessage();//清信息框
			ShowMessge(" File does exist...do you want to Cover it?");
			SetXY(1,20);
			printf("Please make you choose: Y  N");
			do
			{
				SetXY(30,20);
				input(choose,1);
				chooseerr=IsExit(choose,60,17);
				if(chooseerr==0)
				{
					break;
				}    
			}while(1);
			if(choose[0]=='y' || choose[0]=='Y')
			{
				if( (fp=fopen(file,"wb"))==NULL)
				{
					ShowMessge("Cannot open file...enter any key to back");
					getch();
					CleanMenuInfo();
					return 0;
				}
				while(p)
				{
					fwrite(p,LEN,1,fp);
					p=p->next;
				}
				inforsave=0;
				fclose(fp);
				CleaseMessage();//清信息框
				ShowMessge("Save successfully...enter any key to back");
				getch();
				return 1;
			}
			else
			{
				return 0;
			}
		}
		else
		{
			CleaseMessage();//清信息框
			ShowMessge("File cannot be written!enter any key to back");
			getch();
			return 0;
		}
	}
	else
	{	
		if( (fp=fopen(file,"wb"))==NULL)
		{
			ShowMessge("Cannot open file...enter any key to back");
			getch();
			if(flag==0)
				CleanMenuInfo();
			return 0;
		}
		while(p)
		{
			fwrite(p,LEN,1,fp);
			p=p->next;
		}
		fclose(fp);	
		CleaseMessage();//清信息框
		ShowMessge("Save successfully...enter any key to back");
		getch();
		return 1;
	}
}


//导入输入
int LoadData(int count)
{
	int re_input;
	char file[50];
	FILE *fp;
	student *p;
	p=head;	
	//CleanMenuInfo();
	SetXY(35,2);
	printf("Load Stu Data");
	do
	{
		SetXY(5,10);
		printf("Load File Path: ");
		SetXY(1,21);
		printf("Press ESC to back");
		SetXY(21,10);
		re_input =input(file,40);
		if(re_input==1)
			return 0;
		else if(strlen(file)==0)
		{
			ShowMessge("File Path cannot be null!...enter any key to back");
			getch();
			ClearScreen(21,10,78,10);//清除前一次操作
			ClearScreen(1,19,78,20);//清除信息框内容		
		}
	    else if(access(file,0)!=0)
		{
			CleaseMessage();//清信息框
			ShowMessge(" File doesn't exist...enter any key to back");
			getch();
			//CleanMenuInfo();
			//return 0;
			ClearScreen(21,10,78,10);//清除前一次操作
			ClearScreen(1,19,78,20);//清除信息框内容
		}
		else if( (fp=fopen(file,"rb"))==NULL)
		{
			ShowMessge("Cannot open the file...enter any key to back");
			getch();
			//CleanMenuInfo();
			//return 0;   
			ClearScreen(21,10,78,10);//清除前一次操作
			ClearScreen(1,19,78,20);//清除信息框内容
		}
		else 
			break;
	}while(1);
	while(1)
	{
		p=(student *)malloc(LEN);
		fread(p,LEN,1,fp);
		p->next=NULL;
		if(!feof(fp))
			InsertLinkByLast(&head,p);
		else
			break;
		Sno_count++;
	}
	fclose(fp);
	CleaseMessage();
	ShowMessge("Load successfully...enter any key to back");
	getch();
	CleanMenuInfo();
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -