回复:(lixang)困惑的问题
this is a rather easy problem and I would just write the code for you.
=======================================================================
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE* fp;
FILE* fp2;
double x, y, z;
// Problem 1
fp=fopen("out.txt", "w");
if(!fp)
{
printf("cannot open file.\n");
exit(1);
}
fprintf(fp, "%.4f", 0.15);
fclose(fp);
// Problem 2
fp=fopen("a.txt", "r");
if(!fp)
{
printf("cannot open file.\n");
exit(1);
}
fp2=fopen("b.txt", "w");
if(!fp2)
{
printf("cannot open file.\n");
exit(1);
}
while(fscanf(fp, "%lf%lf%lf", &x, &y, &z)!=-1)
fprintf(fp2, "%-8g%-8g%-8g\n", x, y, z);
fclose(fp);
fclose(fp2);
return 0;
}