It's been a while since I've had to do any programming at all so I'm back to basics again
Basically I want to read a list of values from an input file into an array and print the values out again. My code looks like:
Code:
#include <stdio.h>
#include <math.h>
FILE *infile1;
int main()
{
float f0, A, t0, T, t[10], area, f[1800], g[1800], log[1800], tf=4679.45, ti=0.44;
int i;
infile1 = fopen("list.txt","r");
if(infile1 == NULL) {
printf("Could not read file!");
}
else {
for (i=0; i<10; i=i+1) {
t[i]=fgetc(infile1);
printf("%f\n", t[i]);
}
}
return 0;
}
(ignore all the float except for t[10])
The file list.txt simply contains a list of numbers 1 to 10 on separate lines (singly spaced), no other characters. At the moment I just want to get the program to print out these values in the same way but I can't remember how to even do this, how to use fgetc or even if this is the correct function to be using.
The program clearly finds the file but returns a list of 10 random numbers
Help on this much appreciated,
Thanks