Hey guys,
This is my first thread here, so I apologize in advance for breaking any conventions . Anyways, I have been having the most horrible time getting this to work and I know that I have done something similar before. So the gist of it is, I have a small peice of code to read a bunch of numbers on a text file, and store it to a dynamicly sized array. But, I am simply unable to get it to stop at the EOF. This peice of code just gets into an infinite loop. If I replace the num[i-1] with i<= 10, it reads the 10 numbers fine. Any help would really really be appretiated. Thanks in advance.
Code:
for (i = 1; num[i-2] != EOF; i++) {
if (i == x-2) {
x += 10;
num = realloc (num, sizeof (int) * x);
}
fscanf (infile, "%d\n", &num [i-1]);
printf ("%d\n", num[i-1]);
}