圣誕禮物200字作文范文
已知文件中存有庫存產品的記錄,該記錄由產品代碼、產品名稱、單價、數量等域組成,設該文件中的內容是按產品代碼由小到大的順序存儲(產品代碼由1001-1010中間無缺貨)。試編程實現當輸入某產品代碼則打印出該產品記錄的功能。

解:#include
struct product{ int type;
char name[10];
double price;
int number;};
main()
{
FILE *fp;
struct product p;
int size;
int t;
long int i;
size=sizeof(struct product);
printf(“input the type(from 1001 to 1010):”);
scanf(“%d”,&t);
if((fp=fopen(“product”,”rb”))==NULL)
{
printf(“cannot open the file!”);
exit(0);
}
i=(t-1000)*size;
fseek(fp,i,0);
fread(&p,size,1,fp);
printf(“%d %s %f %d\n”,p.type,p.name,p.price,p.number);
fclose(fp);
}
【圣誕禮物200字作文】相關文章:
圣誕禮物的作文11-14
(經典)圣誕禮物的作文09-19
圣誕禮物的作文(精選)01-25
【精選】圣誕禮物的作文02-09
圣誕禮物的作文[精選]01-20
圣誕禮物作文03-16
圣誕禮物的作文[優]02-25
圣誕禮物的作文[推薦]03-15
關于圣誕禮物作文08-22
(精)圣誕禮物的作文11-27
- 相關推薦