高手指教一下呀,小虾感激不尽呀!!!!
刚编了一个下面的东东可是运行有问题,可我找不出问题在那里,请高手指教,小虾感激不尽呀!!!
#include <stdio.h>
#include <stdlib.h>
struct item
{
int code;
char name;
int target;
int sold;
}iarray[50];
struct sales
{
int code;
int quantity;
}sarray[50];
void main()
{
FILE *f1,*f2;
int i=1;
char flag='y';
if((f1=fopen("good.txt","wb+"))==NULL)
{
printf("can not open the file good.txt\n");
exit(1);
}
if((f2=fopen("sale.txt","wb+"))==NULL)
{
printf("can not open the file sale.txt\n");
exit(1);
}
system("cls");
printf("**********ADD NEW ITEM DETAILS***********\n");
printf("\n");
printf("\n");
fseek(f1,0,0);
while(feof(f1)!=1)
{
fread(&iarray[i],sizeof(struct item),1,f1);
i++;
}
iarray[i].code=i;
printf("Item code:%d\n",iarray[i].code);
printf("Enter item name<up to 20 chars.>:");
scanf("%c",&iarray[i].name);
printf("\nEnter target sales:");
scanf("%d",&iarray[i].target);
fseek(f1,(i-1)*sizeof(struct item),0);
fseek(f2,(i-1)*sizeof(struct sales),0);
sarray[i].code=iarray[i].code;
if(fwrite(&iarray[i],sizeof(struct item),1,f1)==1&&fwrite(&sarray[i],sizeof(struct sales),1,f2)==1)
printf("\nRecord write to item file\n");
fclose(f1);
fclose(f2);
}