为什么这个程序用vc++6.0运行时,其他项目都可以正常运行,而第一项却不可以?
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 20
struct text
{char num[20];
char name[10];
char pub[20];
char num1[10];
char pri1[10];
char num2[10];
int pri2;
};
void menu();
void add();
void putin();
void que();
void show();
void exit();
main()
{
int n;
while(1)
{
menu();
printf("\n 请输入您要选择的操作序号,按回车键确认:");
scanf("%d",&n);
switch(n)
{case 1: add();break;
case 2: putin();break;
case 3: que();break;
case 4: show();break;
case 5: return 0;
default: printf("输入错误,请输入列表中存在的序号!\n ");
}
}
}
void menu()
{printf(" ************************* 书店图书销售系统************************ ");
printf("\n 1 图书信息录入");
printf("\n 2 进书处理");
printf("\n 3 售书处理");
printf("\n 4 显示书库现状");
printf("\n 5 退出");
}
void reads(struct text sup[N],int *n)
{
FILE *fp;
int i=0;
if((fp=fopen("e:\\text.dat","rb"))==NULL)
{ printf("文件打开失败!\n");
return;
}
else
{
*n=getw(fp);
for(i=0;i<*n;i++)
fread(&sup[i],sizeof(struct text),1,fp);
}
fclose(fp);
}
void add()/*添加图书信息*/
{FILE *fp;
int n,i,j;
struct text sup;
if((fp=fopen("e:\\text.dat","rb+"))!=NULL)
{j=getw(fp);
rewind(fp);
printf("请输入要添加的图书数量,按回车键确认:");
scanf("%d",&n);
putw(j,fp);
putw(i,fp);
fseek(fp,0L,2);
for(i=1;i<=n;i++)
{ printf("\n请输入第%d个图书的编号,书名,出版社,进购册数,进购价格,出售册数,出售价格用空格分开,并按回车键确认:\n",i);
scanf("%s%s%s%d%s%d%s",sup.num,sup.name,sup.pub,sup.num1,sup.pri1,sup.num2,sup.pri2);
}
}
else
{
if((fp=fopen("e:\\text.dat","wb"))!=NULL)
{
printf("请输入要添加的图书数量,按回车键确认:");
scanf("%d",&n);
putw(n,fp);
for(i=1;i<=n;i++)
{ printf("\n请输入第%d个图书的编号,书名,出版社,进购册数,进购价格,出售册数,出售价格用空格分开,并按回车键确认:\n",i);
scanf("%s%s%s%d%s%d%s",sup.num,sup.name,sup.pub,sup.num1,sup.pri1,sup.num2,sup.pri2);
fwrite(&sup,sizeof(struct text),1,fp);
}
}
}