This program is to read and write into a file
#include <stdio.h>
//read $& write file standardatm.txt. read only alt, temp, pressure
main( )
{
FILE *atmfile, *fpt;
char alt[10],temp[10],pres[10] ;
float a, t, p;
char dummy[10];
int k=0, i=0;
atmfile = fopen("standardatm.txt","r");
fpt=fopen("atm_val1.xls", "w");
fprintf(fpt,"This is an output file\n");
for(k=0;k<98;k++)
{
fscanf(atmfile,"%s",dummy);
}
fscanf(atmfile,"%s %*s %*s %*s %s %s %*s %*s %*s %*s %*s ",alt,temp,pres);
printf("%s %s %s\n",alt, temp, pres);
fprintf(fpt,"%s(km) \t %s(K) \t %s(Nm^-2) \n",alt, temp, pres);
for (i=0;i<42;i++)
{
fscanf(atmfile,"%f %*f %*f %*f %f %f %*f %*f %*f %*f %*f \n ", &a, &t,&p);
printf("%4.1f %4.1f %6.f \n",a, t, p);
fprintf(fpt,"%4.1f \t %4.1f \t %6.f \n",a, t, p);
}
fclose(atmfile);
fclose(fpt);
}
Pages: 1 2