C语言关于文件操作的问题,高手来

此题目意思为,制作一个小型的信息管理,我编写的程序可以登入保存信息,但是在修改和删除信息上出了问题.我认为是数组上没有编写好,希望高手帮忙看看,查查错误.
我就10分了,全奉上!!!
代码:
#include<stdio.h>
#include<conio.h>
struct date
{
long int xuehao;
char name[20];
int score;
}date[60];
FILE *fp;
int i,j,n,m,k;
long int id;
char ch;
void main()
{
for(i=0;i<60;i++)
{
clrscr();
printf("\n 1.Setting information");
printf("\n 2.Delete information");
printf("\n 3.Modefy information");
printf("\n 4.Find information");
printf("\n 5.Exit system ");
printf("\n What do you want to do ! ");
scanf("%d",&n);
switch(n)
{
case 1:
{
if((fp=fopen("c:\\xinxi.txt","a+"))==NULL)
{printf("wrong!"); exit(1);}
for(j=0;j<60;j++)
{
clrscr();
printf("\nPlease input your id:");
scanf("%ld",&date[j].xuehao);
printf("\nPlease input your name:");
scanf("%s",&date[j].name);
printf("\nPlease input your score:");
scanf("%d",&date[j].score);
fprintf(fp,"%2ld %10s %3d\n",date[j].xuehao,date[j].name,date[j].score);
printf("Do you want to continue ? y/n");
do{ch=getchar();} while(ch!='n'&&ch!='N'&&ch!='y'&&ch!='Y');
if(ch=='n'||ch=='N') break;
}fclose(fp);
break;
}

第1个回答  2010-01-16
接着补充上面的:
case 2:
{
for(m=0;m<100;m++)
{
clrscr();
if((fp=fopen("c:\\xinxi.txt","r+"))==NULL)
{printf("wrong"); getch(); exit(1);}
for(k=0;k<100;k++)
{
fscanf(fp,"%ld%s%d",&date[k].xuehao,&date[k].name,&date[k].score);
if(fgetc(fp)==-1) break;
}fclose(fp);
printf("\nPlease input your id:");
scanf("%ld",&id);
for(i=0;i<60;i++) if(date[i].xuehao==id) break;
for(j=i;j<60;j++)
{
date[j].xuehao=date[j+1].xuehao;
strcpy(date[j].name,date[j+1].name);
date[j].score=date[j].score;
}
if((fp=fopen("c:\\xinxi.txt","w+"))==NULL)
{printf("wrong");getch(); exit(1);}
for(i=0;i<k-1;j++) fprintf(fp,"%2ld %10s %3d",date[i].xuehao,date[i].name,date[i].score);
printf("Do you want to continue ? y/n");
do{ch=getchar();} while(ch!='n'&&ch!='N'&&ch!='y'&&ch!='Y');
if(ch=='n'||ch=='N') break;
}fclose(fp);
break;
}
case 3:
{
for(m=0;m<100;m++)
{
clrscr();
if((fp=fopen("c:\\xinxi.txt","r+"))==NULL)
{printf("wrong"); getch(); exit(1);}
for(k=0;k<100;k++)
{fscanf(fp,"%ld%s%d",&date[k].xuehao,&date[k].name,&date[k].score);
if(fgetc(fp)==-1) break;
}fclose(fp);
printf("\nPlease input your id:");
scanf("%ld",&id);
for(i=0;i<k;i++) if(date[i].xuehao==id) break;
printf("\nThe name you want to rewrite:");
scanf("%s",&date[i].name);
printf("\nThe score you want to rewrite:");
scanf("%d",&date[i].score);
if((fp=fopen("c:\\xinxi.txt","w+"))==NULL)
{printf("wrong");getch(); exit(1);}
for(j=0;j<k;j++); fprintf(fp,"%2ld %10s %3d",date[j].xuehao,date[j].name,date[j].score);
printf("Do you want to continue ? y/n");
do{ch=getchar();} while(ch!='n'&&ch!='N'&&ch!='y'&&ch!='Y');
if(ch=='n'||ch=='N') break;
}fclose(fp);
break;
}
case 4:
{
clrscr();
if((fp=fopen("c:\\xinxi.txt","r+"))==NULL)
{printf("wrong"); exit(1);}
printf("\nPlease input your id:");
scanf("%ld",&id);
for(i=0;i<100;i++)
{
fscanf(fp,"%ld%s%d",&date[i].xuehao,&date[i].name,&date[i].score);
if(date[i].xuehao==id) break;
}
printf("\nxuehao name score ");
printf("\n%ld %s %d",date[i].xuehao,date[i].name,date[i].score);
printf("\nPress any key to go back"); getch();
fclose(fp);
break;
}
}
if(n==5) break;
}
}
第2个回答  2010-01-16
百度知道应该弄些格式,便于看代码,要不然没法看,容量也有点小,哎本回答被网友采纳
第3个回答  2010-01-24
太长了,我也不会,呵呵!
相似回答