just signed up as I'm pretty sure you can help me with a few things!
I'm pretty new to C, so my code will probably be ridden with noob errors... But... Here it goes!
I'm trying to write a program which reads a set of numbers from a txt file and puts them into an array; trouble is I keep having trouble with EOF errors, which loop type to use etc.
The numbers are stored in the txt file like this:
So, a new number each line, and only integer numbers.
My code so far is:
It seems to find the number of digits in the txt file ok, which is the variable n, but further than that it doesn't do much. It also compiles completely fine.
#define TXTFILE "numbers.txt"
FILE *FPTR; //File Pointer
int numint; //Integer variable to store File contents
int numbarr; //Array to store file contents
int i=0; //Iteration counter
int n; //Integer variable to contain the number of values in the file
printf("Number Analysis Tool\n");
FPTR = fopen(TXTFILE,"r");
printf("File is missing, empty or corrupted.\n");
printf("File opened successfully.\n");
while((numint = fgetc(FPTR)) != EOF)
printf("Number of digits within the txt file: %d\n", n);
while((numint = fgetc(FPTR)) != EOF && i>=0 && i<=n)
Any help is much appreciated!