#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "conio.h"
#include "mem.h"
#include "ctype.h"
#include "alloc.h"
struct score
{
char gukehao[8];
char mingzi[20];
float score[6];
}data,info[1000];
int i,j,k=0;
float n;
char temp[20],ch;
FILE *fp,*fp1;
void luru()
{
if((fp=fopen("s_score.txt","ab+"))==NULL)
{
printf("cannot open this file.\n");
getch();exit(0);
}
for(i=0;i>=0;i++)
{
printf("Please input gukehao:");
gets(data.gukehao);
printf("please input mingzi:");
gets(data.mingzi);
printf("Please input xiaofei:");
gets(temp);data.score[0]=atof(temp);
if(data.score[0]<=5000)
n=1;
else
if(data.score[0]<=10000&&data.score[0]>5000)
n=0.95;
else
n=0.9;
fwrite(&data,sizeof(data),1,fp);
printf("another?(input n to main/anykey to continue)\n");
ch=getch();
if(ch=='n'||ch=='N')
break;
} fclose(fp);
}
void xiugai()
{
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
{
printf("Cannot open this file.\n");
exit(0);
}
printf("\nPlease input shuru xiugai gukehao:");
scanf("%d",&i); getchar();
while((fread(&data,sizeof(data),1,fp))==1)
{
j=atoi(data.gukehao);
if(j==i)
{
printf("gukehao:%s\nmingzi:%s\n",data.gukehao,data.mingzi);
printf("Please input mingzi:");
gets(data.mingzi);
printf("Please input xiaofei:");
gets(temp);data.score[0]=atof(temp);
} fwrite(&data,sizeof(data),1,fp1);
}
fseek(fp,0L,0);
fseek(fp1,0L,0);
while((fread(&data,sizeof(data),1,fp1))==1)
{
fwrite(&data,sizeof(data),1,fp);
}
fclose(fp);
fclose(fp1);
}
void chazhao()
{
if((fp=fopen("s_score.txt","rb"))==NULL)
{
printf("\nCannot open this file.\n");
exit(0);
}
printf("\nPlease input gukehao chakan:");
scanf("%d",&i);
while(fread(&data,sizeof(data),1,fp)==1)
{
j=atoi(data.gukehao);
if(i==j)
{
printf("gukehao:%s\nmingzi:%s\nxiaofei:%f\njifen:%f\nzhekou:%f\n",data.gukehao,data.mingzi,data.score[0],data.score[0],n);
}
}getch();
}
void shanchu()
{
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
{
printf("\nopen score.txt was failed!");
getch();
exit(0);
}
printf("\nPlease input gukehao which you want to del:");
scanf("%d",&i);getchar();
while((fread(&data,sizeof(data),1,fp))==1)
{
j=atoi(data.gukehao);
if(j==i)
{
printf("Anykey will delet it.\n");
getch();
continue;
}
fwrite(&data,sizeof(data),1,fp1);
}
fclose(fp);
fclose(fp1);
remove("s_score.txt");
rename("temp.txt","s_score.txt");
printf("Data delet was succesful!\n");
printf("Anykey will return to main.");
getch();
}
main()
{
while(1)
{
clrscr();
printf("* ========================================================= * \n");
printf("* 1>luru 2>xiugai * \n");
printf("* 3>shanchu 4>chazhao * \n");
printf("* 5>exit * \n");
printf("* * \n");
printf("* --------------------------------------------------------- * \n");
printf(" Please input which you want(1-5):\n");
ch=getch();
switch(ch)
{
case '1':luru();break;
case '2':xiugai(); break;
case '3':shanchu(); break;
case '4':chazhao(); break;
case '5':exit(0);
default: continue;
}
}
}
- 1
- 2
前往页