本文介绍了使用结构进行文件写入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include
#include
calc(struct salesdata *salesptr);
struct salesdata{
		char transno[4];
		int salesno;
		int prodno;
		int unit_sold;
		float value_of_sale;
		};
void main()
{

FILE *fp;
struct salesdata salesrec,*ptr;
clrscr();
ptr=fopen("rand.txt","w");
printf("Enter transsaction no: ");
scanf("%3s",salesrec.transno);
fflush(stdin);

printf("Enter salesman no: ");
scanf("%d",&salesrec.salesno);
fflush(stdin);

printf("Enter the product number: ");
scanf("%d",&salesrec.prodno);
fflush(stdin);

printf("Enter unit sold: ");
scanf("%d",&salesrec.unit_sold);
fflush(stdin);

(float)salesrec.value_of_sale=calc(&salesrec);
printf("Value of sale: %f");

ptr=&salesrec;
fwrite(ptr, sizeof(struct salesdata),1,fp);


getch();
}
calc(struct salesdata *salesptr)
{
static float prod_rate[4]={ 12.0, 65.0, 30.0, 20.5 };
salesptr->value_of_sale=(float)salesptr->unit_sold* prod_rate[salesptr->prodno-1];
return salesptr->value_of_sale;
}


我正在将记录写入rand.txt文件.编写工作已完成,但已以编码形式显示.因此,请提供帮助....


I''m writing the record to rand.txt file. Writing is being done but it''s shown in an encoded form. So, please help....

推荐答案



这篇关于使用结构进行文件写入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 17:43
查看更多