So I got this question where we are given a data (txt) file. We need to read it into an array, then report the first, fifth, and last entries of that file. Here is the code that I have thus far. It's reading the first, but the other two are wrong. Any help would be appreciated.
#include <stdio.h>
int main(void)
{
int index ;
int N = 0 ;
double x[100] ;
FILE * input ;
input = fopen("weights.txt", "r") ;
if (input == NULL)
{
printf("failed to open input file\n") ;
system("PAUSE") ;
return (0) ;
}
while(fscanf(input,"%lf", &x) == 1)
{
N++ ;
}
printf("The first value in the text file is %g\n", x[0]) ;
printf("The fifth value in the text file is %g\n", x[4]) ;
printf("The last value is the text file is %g\n", x[N]) ;
printf("The number of values = %i\n", N) ;
system("PAUSE") ;
return (0) ;
}