用C语言开发小型大数据库管理系统代码文库 1.docx
《用C语言开发小型大数据库管理系统代码文库 1.docx》由会员分享,可在线阅读,更多相关《用C语言开发小型大数据库管理系统代码文库 1.docx(21页珍藏版)》请在冰豆网上搜索。
用C语言开发小型大数据库管理系统代码文库1
用C语言开发小型数据库管理系统代码的文库.txt如果有来生,要做一棵树,站成永恒,没有悲伤的姿势。
一半在土里安详,一半在风里飞扬,一半洒落阴凉,一半沐浴,非常沉默非常骄傲,从不依靠从不寻找。
#include
#include
typedefstructcount{/*保存记录条数结构体*/
charname[10];
intnum;
}count;
typedefstructst{
charname[10];
longNumber;
intMath;
intC;
intAmount;
}st;
strecord[8];
countnum[1];
charfilename[10]={"0"};
charfilename2[10]={"0"};
intInputnum[8];
voidMainMenu(){/*主菜单*/
printf("\n\t\t\t\t**********\n");
printf("\t\t\t\t*主菜单*\n");
printf("\t\t\t\t*1.创建新文件*\n");
printf("\t\t\t\t*2.添加记录*\n");
printf("\t\t\t\t*3.删除记录*\n");
printf("\t\t\t\t*4.排序*\n");
printf("\t\t\t\t*5.查询记录*\n");
printf("\t\t\t\t*6.退出*\n");
printf("\t\t\t\t**********\n");
}
voidDelMenu(){/*删除菜单*/
printf("\n\t\t\t\t************\n");
printf("\t\t\t\t*删除菜单*\n");
printf("\t\t\t\t*1.学号查询删除*\n");
printf("\t\t\t\t*2.返回到上级菜单*\n");
printf("\t\t\t\t************\n");
}
voidRankingMenu(){/*排序菜单*/
printf("\n\t\t\t\t************\n");
printf("\t\t\t\t*排序菜单*\n");
printf("\t\t\t\t*1.数学成绩排序*\n");
printf("\t\t\t\t*2.C语言成绩排序*\n");
printf("\t\t\t\t*3.总分排序*\n");
printf("\t\t\t\t*4.返回到上级菜单*\n");
printf("\t\t\t\t************\n");
}
voidInquireMenu(){/*查讯菜单*/
printf("\n\t\t\t\t************\n");
printf("\t\t\t\t*查讯菜单*\n");
printf("\t\t\t\t*1.学号查讯*\n");
printf("\t\t\t\t*2.查讯*\n");
printf("\t\t\t\t*3.数学成绩查讯*\n");
printf("\t\t\t\t*4.C语言成绩查讯*\n");
printf("\t\t\t\t*5.总分查讯*\n");
printf("\t\t\t\t*6.返回到上级菜单*\n");
printf("\t\t\t\t************\n");
}
charInputfilename(){/*输入文件名同时产生付本文件名*/
charstr2[]={"B"};
printf("**请输入文件名**:
");
scanf("%s",filename);
getchar();
strcpy(filename2,filename);
strcat(filename2,str2);
}
FILE*readfile(){/*读取文档*/
FILE*fp1;
if((fp1=fopen(filename,"rb"))==NULL)
{printf("\n文件读取错误!
!
\n");
fclose(fp1);
}
return(fp1);
}
FILE*foundfile(){/*新建文档*/
FILE*fp1;
if((fp1=fopen(filename,"wb"))==NULL)
{printf("\n文件创建错误!
!
\n");
fclose(fp1);
}
return(fp1);
}
FILE*savefile(){/*追加文档*/
FILE*fp1;
if((fp1=fopen(filename,"ab"))==NULL)
{printf("\n文件追加错误!
!
\n");
fclose(fp1);
}
return(fp1);
}
intInputSave(){/*添加数据*/
inti=0,j;
charch='y';
while(ch!
='w')
{i=i+1;
printf("\n**请输入(字符型)**:
");
scanf("%s",record[i].name);
Loop1:
printf("\n**请输入学号(长整型)**:
");
scanf("%ld",&record[i].Number);
if(i!
=1)
for(j=1;j
if(record[i].Number==record[j].Number)
{printf("\n\t警告!
输入了二个同样的学号!
第%d条和第%d学号相同!
\n",i,j);
printf("\n\t请重新输入!
\n");
gotoLoop1;
}
Loop2:
printf("\n**请输入数学成绩(整型)**:
");
scanf("%d",&record[i].Math);
if(record[i].Math>100||record[i].Math<0)
{printf("\n\t输入的分数不服合实际要求!
请重新录入!
\n");
gotoLoop2;
}
Loop3:
printf("\n**请输入C语言成绩(整型)**:
");
scanf("%d",&record[i].C);
if(record[i].C>100||record[i].C<0)
{printf("\n\t输入的分数不服合实际要求!
请重新录入!
\n");
gotoLoop3;
}
record[i].Amount=record[i].Math+record[i].C;
printf("\n'w'=结束录入's'=重新录入此条记录'n'=下一条:
");
getchar();/*吃掉上一个回车符*/
if((ch=getchar())=='s')
i=i-1;
}
return(i);
}
/*
voidReadComputer(inti,FILE*fp1){(文本方式)数据写入机器
intj;
for(j=1;j
fscanf(fp1,"%s,%ld,%d,%d,%d",record[j].name,&record[j].Number,&record[j].Math,&record[j].C,&record[j].Amount);
}
voidSaveFile(inti,FILE*fp1){(文本方式)数据写到文件中
intj;
for(j=1;j
fprintf(fp1,"%s,%ld,%d,%d,%d",record[j].name,record[j].Number,record[j].Math,record[j].C,record[j].Amount);
}
*/
voidReadComputer2(inti,FILE*fp1){/*(2方式)数据写入机器*/
intj;
for(j=1;j
if((fread(&record[j],sizeof(structst),1,fp1))!
=1)
{printf("\n主文件数据读取错误!
\n");
fclose(fp1);
}
}
voidSaveFile2(inti,FILE*fp1){/*(2方式)数据写到文件中*/
intj;
for(j=1;j
if((fwrite(&record[j],sizeof(structst),1,fp1))!
=1)
{printf("\n主文件数据写入错误!
\n");
fclose(fp1);
}
}
/*************************************************************************************************************************/
FILE*readfile2(){/*读文件付本*/
FILE*fp1;
if((fp1=fopen(filename2,"rb"))==NULL)
{printf("\n付本文件读取错误!
\n");
fclose(fp1);
}
return(fp1);
}
FILE*foundfile2(){/*新建文件付本*/
FILE*fp1;
if((fp1=fopen(filename2,"wb"))==NULL)
{printf("\n付本文件创建错误!
\n");
fclose(fp1);
}
return(fp1);
}
FILE*savefile2(){/*追加文件付本*/
FILE*fp1;
if((fp1=fopen(filename2,"ab"))==NULL)
{printf("\n付本文件追加错误!
\n");
fclose(fp1);
}
return(fp1);
}
/*
voidAdditive2(inti,FILE*fp1){数据与入付本文件(文本方式)
intj;
charstr2={"0"};
if(strcmp(filenameF,str2)!
=0)
strcpy(num[0].name,filenameF);
else
strcpy(num[0].name,filenameA);
num[0].num=i;
fprintf(fp1,"%s,%d",num[0].name,num[0].num);
}
intReadComputer2(FILE*fp1){读出付本中的数据(文本方式)
intj,k;
fscanf(fp1,"%s,%d",num[0].name,&num[0].num);
k=num[0].num;
return(k);
}
*/
voidAdditive2Two(inti,FILE*fp1){/*数据写入付本文件(二进制方式)*/
charstr2[]={"0"};
if(strcmp(filename2,str2)!
=0)
strcpy(num[0].name,filename2);
else
strcpy(num[0].name,filename2);
num[0].num=i;
if((fwrite(&num[0],sizeof(structcount),1,fp1))!
=1)
{printf("\n付本文件数据写入错误!
\n");
fclose(fp1);
}
}
intReadComputer2Two(FILE*fp1){/*读出付本中的数据(二进制方式)*/
intj;
if((fread(&num[0],sizeof(structcount),1,fp1))!
=1)
{printf("\n付本文件数据读取错误!
\n");
fclose(fp1);
}
j=num[0].num;
return(j);
}
/*************************************************************************************************************************/
voidNum_inquire(){/*学号查询*/
intnum,j,time;
FILE*fp1,*fp2;
fp1=readfile();/*读取文档*/
fp2=readfile2();/*(开打方式'读'**'引用读文件名')读文件付本*/
time=ReadComputer2Two(fp2);/*读出付本中的数据(二进制方式)*/
ReadComputer2(time,fp1);/*(2方式)数据写入机器*/
fclose(fp1);fclose(fp2);
printf("输入学号:
");
scanf("%ld",&num);
/*getchar();*/
for(j=1;j