用fprintf(文件地址,“%f”,float型变量名);就这样能写进去,比如文件是FILE *fp;
float fDat; 就是fprintf(fp,"%f",fDat);
#include
#include
int main()
{
FILE *fp;
float x;
char name[50];
printf("Please input a float data:\n");
scanf("%f",&x);
printf("Please input a file name to create a file and store your float data:\n");
scanf("%s",name);
if((fp=fopen(name,"w"))==NULL) return -1;
fprintf(fp,"%g",x);
fclose(fp);
printf("Now,%g has been saved to %s.\n",x,name);
system("pause");
return 0;
}