|
|
|
|
#include<stdio.h>
|
|
|
|
|
#include<stdlib.h>
|
|
|
|
|
#include<conio.h>
|
|
|
|
|
#include<string.h>
|
|
|
|
|
struct infor {
|
|
|
|
|
char ID[50];
|
|
|
|
|
char NAME[50];
|
|
|
|
|
float PRICE;
|
|
|
|
|
long NUMBER;
|
|
|
|
|
}g[1000],m[1000],x;
|
|
|
|
|
struct inf {
|
|
|
|
|
char id[50];
|
|
|
|
|
char name[50];
|
|
|
|
|
float price;
|
|
|
|
|
long number;
|
|
|
|
|
}c;
|
|
|
|
|
//struct infor g[1000];
|
|
|
|
|
FILE *p;
|
|
|
|
|
void menu_s();
|
|
|
|
|
void input();
|
|
|
|
|
void output();
|
|
|
|
|
void check();
|
|
|
|
|
void updata();
|
|
|
|
|
void add();
|
|
|
|
|
void dele();
|
|
|
|
|
void dele2();
|
|
|
|
|
int len();
|
|
|
|
|
int len2();
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
system("cls");//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
int n;
|
|
|
|
|
menu_s();
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
while(n)
|
|
|
|
|
{
|
|
|
|
|
system("cls");
|
|
|
|
|
|
|
|
|
|
switch(n)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
input() ;break;
|
|
|
|
|
case 2:
|
|
|
|
|
output();break;
|
|
|
|
|
case 3:
|
|
|
|
|
updata();break;
|
|
|
|
|
case 4:
|
|
|
|
|
check();break;
|
|
|
|
|
case 5:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
getch();
|
|
|
|
|
menu_s();
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void menu_s ()
|
|
|
|
|
{
|
|
|
|
|
printf("----------------------------\n");
|
|
|
|
|
printf("***********<2A><><EFBFBD>˵<EFBFBD>***********\n");
|
|
|
|
|
printf("*********1:<3A><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>*********\n");
|
|
|
|
|
printf("*********2:<3A><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>*********\n");
|
|
|
|
|
printf("*********3:<3A><><EFBFBD>¿<EFBFBD><C2BF><EFBFBD>*********\n");
|
|
|
|
|
printf("*********4:<3A><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>*********\n");
|
|
|
|
|
printf("*********5:<3A>˳<EFBFBD>ϵͳ*********\n");
|
|
|
|
|
printf("*********<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>*********\n");
|
|
|
|
|
printf("----------------------------\n");
|
|
|
|
|
}
|
|
|
|
|
void input()
|
|
|
|
|
{
|
|
|
|
|
int i=0,s;
|
|
|
|
|
//struct infor g;
|
|
|
|
|
char next[2]="y";
|
|
|
|
|
p=fopen("1.txt","wb+");
|
|
|
|
|
if(p==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʧ<EFBFBD><EFBFBD>\n");
|
|
|
|
|
fclose(p);
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
while(strcmp(next,"y")==0||strcmp(next,"Y")==0)
|
|
|
|
|
{
|
|
|
|
|
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
scanf("%s",g[i].ID );
|
|
|
|
|
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
scanf("%s",&g[i].NAME );
|
|
|
|
|
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD>۸<EFBFBD>\n");
|
|
|
|
|
scanf("%f",&g[i].PRICE );
|
|
|
|
|
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
scanf("%d",&g[i].NUMBER );
|
|
|
|
|
fwrite(&g[i],sizeof(struct infor),1,p);/*<2A><><EFBFBD>ļ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|
|
|
|
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>루y(Y)/n(N)<29><>\n");
|
|
|
|
|
fflush(stdin);//<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
i++;
|
|
|
|
|
//next=getch();
|
|
|
|
|
scanf("%s",next);
|
|
|
|
|
}
|
|
|
|
|
fclose(p);
|
|
|
|
|
}
|
|
|
|
|
int len()//<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{ int z=0;
|
|
|
|
|
p=fopen("1.txt","r+");
|
|
|
|
|
if(p==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʧ<EFBFBD><EFBFBD>\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
rewind(p);//<2F><><EFBFBD>ļ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ͷ<EFBFBD><CDB7>
|
|
|
|
|
while(!feof(p))
|
|
|
|
|
{
|
|
|
|
|
if((fread(&g[z],sizeof(struct infor),1,p))==1);
|
|
|
|
|
z++;
|
|
|
|
|
}
|
|
|
|
|
fclose(p);
|
|
|
|
|
return z-1;
|
|
|
|
|
}
|
|
|
|
|
int len2()//<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{ int z=0;
|
|
|
|
|
FILE *fp;
|
|
|
|
|
fp=fopen("3.txt","r+");
|
|
|
|
|
if(fp==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʧ<EFBFBD><EFBFBD>\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
rewind(fp);//<2F><><EFBFBD>ļ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ͷ<EFBFBD><CDB7>
|
|
|
|
|
while(!feof(fp))
|
|
|
|
|
{
|
|
|
|
|
if((fread(&c,sizeof(struct inf),1,fp))==1);
|
|
|
|
|
z++;
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
return z;
|
|
|
|
|
}
|
|
|
|
|
void check()
|
|
|
|
|
{
|
|
|
|
|
int i,s=0;
|
|
|
|
|
long length;
|
|
|
|
|
p=fopen("1.txt","rb+");
|
|
|
|
|
if(p==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʧ<EFBFBD><EFBFBD>\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
printf("\n----------------------------------------------------\n<EFBFBD><EFBFBD>Ʒ<EFBFBD>б<EFBFBD>\n----------------------------------------------------\n");
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\t\tƷ<EFBFBD><EFBFBD>\t\t<EFBFBD>۸<EFBFBD>\t\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
rewind(p);//<2F><><EFBFBD>ļ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ͷ<EFBFBD><CDB7>
|
|
|
|
|
/* while(!feof(p))
|
|
|
|
|
{
|
|
|
|
|
if((fread(&g[s],sizeof(struct infor),1,p))==1);
|
|
|
|
|
s++;
|
|
|
|
|
}*/
|
|
|
|
|
s=len();
|
|
|
|
|
rewind(p);
|
|
|
|
|
fread(g,sizeof(struct infor),s,p);
|
|
|
|
|
for(i=0;i<s;i++)
|
|
|
|
|
printf("%-10s\t%s\t\t%.1f\t\t%ld\n",g[i].ID ,g[i].NAME ,g[i].PRICE,g[i].NUMBER );
|
|
|
|
|
printf("----------------------------------------------------\n");
|
|
|
|
|
fclose(p);
|
|
|
|
|
}
|
|
|
|
|
void output()
|
|
|
|
|
{
|
|
|
|
|
FILE *p,*fp;
|
|
|
|
|
char a[50],next[2]="y";
|
|
|
|
|
int i,j,l,sum=0,num=0,s;
|
|
|
|
|
p=fopen("1.txt","rb+");
|
|
|
|
|
fp=fopen("3.txt","wb+");
|
|
|
|
|
while(strcmp(next,"y")==0||strcmp(next,"Y")==0)
|
|
|
|
|
{
|
|
|
|
|
l=len();
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>۳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
scanf("%s",&a[50]);
|
|
|
|
|
for(i=0;i<l;i++)
|
|
|
|
|
{
|
|
|
|
|
fseek(p,sizeof(struct infor)*(i),0);
|
|
|
|
|
fscanf(p,"%s%s%d%d",&c.id ,&c.name ,&c.price ,&c.number );
|
|
|
|
|
//printf("%-10s\t%s\t\t%.1f\t\t%ld\n",c.id ,c.name ,c.price ,c.number);
|
|
|
|
|
if(strcmp(a,c.name )==0)
|
|
|
|
|
{
|
|
|
|
|
fwrite(&c,sizeof(struct inf),1,fp);
|
|
|
|
|
printf("%-10s\t%s\t\t%.1f\t\t%ld\n",c.id ,c.name ,c.price ,c.number);
|
|
|
|
|
fclose(p);
|
|
|
|
|
void dele2( char a[50] );
|
|
|
|
|
sum++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>루y(Y)/n(N)<29><>\n");
|
|
|
|
|
scanf("%s",next);
|
|
|
|
|
}
|
|
|
|
|
s=len2();
|
|
|
|
|
fp=fopen("3.txt","rb+");
|
|
|
|
|
printf("\n----------------------------------------------------\n<EFBFBD><EFBFBD>Ʒ<EFBFBD>б<EFBFBD>\n----------------------------------------------------\n");
|
|
|
|
|
for(i=0;i<s;i++)
|
|
|
|
|
{
|
|
|
|
|
fseek(fp,sizeof(struct inf)*(i),0);
|
|
|
|
|
fscanf(fp,"%s%s%d%d",&c.id ,&c.name ,&c.price ,&c.number );
|
|
|
|
|
num+=c.price ;
|
|
|
|
|
printf("%-10s\t%s\t\t%.1f\t\t%ld\n",c.id ,c.name ,c.price ,c.number);
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>۶\t\t\t\t\t%d\n",num);
|
|
|
|
|
}
|
|
|
|
|
fclose(fp);
|
|
|
|
|
printf("----------------------------------------------------");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updata()
|
|
|
|
|
{
|
|
|
|
|
int a;
|
|
|
|
|
printf("\n<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>1ɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>Ϣ\n");
|
|
|
|
|
scanf("%d",&a);
|
|
|
|
|
switch(a)
|
|
|
|
|
{
|
|
|
|
|
case 2:add();break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void add()
|
|
|
|
|
{
|
|
|
|
|
FILE *P;
|
|
|
|
|
int i=0;
|
|
|
|
|
char next[2]="y";
|
|
|
|
|
|
|
|
|
|
//i=len();
|
|
|
|
|
//fseek(p,0l,2);
|
|
|
|
|
while(strcmp(next,"y")==0||strcmp(next,"Y")==0)
|
|
|
|
|
{
|
|
|
|
|
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
scanf("%s",&g[i].ID );
|
|
|
|
|
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
scanf("%s",&g[i].NAME );
|
|
|
|
|
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD>۸<EFBFBD>\n");
|
|
|
|
|
scanf("%f",&g[i].PRICE );
|
|
|
|
|
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
scanf("%d",&g[i].NUMBER );
|
|
|
|
|
|
|
|
|
|
p=fopen("1.txt","ab");
|
|
|
|
|
if(p==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʧ<EFBFBD><EFBFBD>\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
fwrite(&g[i],sizeof(struct infor),1,p);/*<2A><><EFBFBD>ļ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|
|
|
|
fclose(p);
|
|
|
|
|
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>루y(Y)/n(N)<29><>\n");
|
|
|
|
|
//fflush(stdin);//<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
//i++;
|
|
|
|
|
//next=getch();
|
|
|
|
|
scanf("%s",next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|