#include <stdio.h>
main ()
{
FILE *file, *resourcePtr;
int i;
int no[3]={1,2,3};
char name [3][10] ={{"可乐"},{"面包"}, {"牛奶"}};
int price[3]={3,2,2};
file=fopen("resource.dat", "w");
for (i=0; i<3; i++) {
fprintf(file, "%d%s%d\n", no[i], name[i], price[i]);
printf("%d%s%d\n", no[i], name[i], price[i]);
}
fclose (file);
resourcePtr=fopen("resource.dat", "r");
for (i=0; i<3; i++) {
fscanf(resourcePtr, "%d%s%d", no[i], name[i], price[i]); //运行到这出错,为什么?请指正
printf("%d%s%d\n", no[i], name[i], price[i]);
}
fclose (resourcePtr);
}