/* Preprocessor directives */
#include <stdio.h>
#include <math.h>
#define inputfile "C:\\Users\\Luke Wagner\\Desktop\\ENGR 200\\trains.txt"
#define outputfile "C:\\Users\\Luke Wagner\\Desktop\\ENGR 200\\train_results.txt"
/* Main Function */
int main(void)
{
/* Declare Variables */
double a,f;
int ndata,i,TrainID, m, d, iveloc,fveloc;
char quit;
FILE *trains, *train_results;
/* Open Files */
trains = fopen(inputfile,"r");
train_results = fopen(outputfile,"w");
/* Scan to Check for File */
/* Scan to check for file */
if(trains == NULL)
{
printf("\n\nError opening input file occurred\n\n");
printf("\n\nProgram Terminated\n\n");
}
else
{
/* Print Headings */
printf("Stopping Force Program\n");
printf("by Luke Wagner\n\n");
printf("Train ID Mass I-Velocity F-Velocity Distance Force \n");
printf(" (lbs) (ft/sec) (ft\sec) (ft) (lbs) \n");
/* Print to file */
fprintf(train_results,"Stopping Force Program\n");
fprintf(train_results,"by Luke Wagner\n\n");
fprintf(train_results,"Train ID Mass I-Velocity F-Velocity Distance Force \n");
fprintf(train_results," (lbs) (ft/sec) (ft\sec) (ft) (lbs) \n");
/* Scan File */
fscanf(trains,"%i",&ndata);
for(i=1;i<=ndata;i++)
{
/* Store Data */
fscanf(trains,"%i %i %i %i %i",&TrainID,&m,&iveloc,&fveloc,&d);
/* Calculations */
a=(pow(fveloc,2.0)-pow(iveloc,2.0))/(2.0*d);
f=(m*a);
/* Print results */
printf("%i %i %4i %4i %i %9i \n",TrainID,m,iveloc,fveloc,d,f);
fprintf(train_results,"i %i %4.1i %4.1i %i %9.1i \n",TrainID,m,iveloc,fveloc,d,f);
}
/* Quit */
printf("\n\n\nEnter Q TO QUIT. \n");
do
{
quit = getchar();
}
while (quit != 'q');
return 0;
}
}
The output is supposed to look like this:

And the input file is this:
5
2221 200000 75.5 25.0 2000
3582 300000 65.2 18.0 4000
3468 400000 88.0 35.0 3500
7635 150000 55.5 25.5 2500
6543 555000 65.7 9.5 3200