i am suppose to read a file of munbers, ist row column is the time, 2nd column is the distance, program issuppose to print out the number of rows, maximum distance and minimum distance with their respective times. i am suppost to use a sentinel of -1 . i am almost done with the codes, but it doesn't seem to be reading propely.

#include<stdio.h>

#include<stdlib.h>

#include<io.h>

#define Sentinel -1

void main()

{

int i,rows;

double time,min_time,max_time;

double distance,min_dist, max_dist;

FILE *rocket;

FILE *data;

rocket = fopen("rocket.txt","r");

if(rocket==NULL)

{

printf("file not found\n");

}

else

{

fscanf(rocket,"%f",&rows);

printf("Number of rows:%f ", rows);

}

for(i=0;i<50;++i)

{

fscanf(rocket,"%d%d",&time,&distance);

if(distance>max_dist)

{

max_dist=distance;

max_time=time;

}

if(distance<min_dist)

{

min_dist=distance;

min_time=time;

}

}

fclose(rocket);

data=fopen("data.txt","w");

fprintf(data,"Minimum Distance = %4.1d (Time = %d)",min_dist,min_time);

fprintf(data,"Maximum Distance = %4.1d (Time = %d)",max_dist,max_time);

fclose(data);

}

0.0 0.0

30.0 5000.0

60.6 25000.0

90.0 60000.0

100.0 75000.0

110.0 30000.0

140.0 10000.0

170.0 2500.0

200.0 0.0

-1.0 -1.0

I am unlocking this question in preparation for cleanup. I will return in 7 days to finalize this question. Please leave any recommendations for the final state of this question, I will take all recommendations into consideration. Failing any feedback, I may decide in 7 days to delete or PAQ this question with no refund. Thanks.

SpideyMod

Community Support Moderator @Experts Exchange