Hey, I'm new to this so hi
I've a .txt file with 96 numbers in it
eg.
2719
1058
4021
...
I need a while loop to read how many numbers there are in the .txt file because the file changes and the number of numbers changes.
EOF was used but I'm not really clear on that.
Heres my sexeh code
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *fp;
int i, c;
fp = fopen("elec_load_data.txt", "r");
i=0;
while ((c = fgetc(fp)) != EOF)
{
putchar (c);
i++;
printf("%d\n", i); // to see if the counter is counting
}
fclose(fp);
return 0;
}