I have recently run into an issue where my program will read some numbers from a file and then stop reading them.
In the next code:
Code:
int A[20];
int B[20];
Code:
for(k=0 ; k < 20 ; k++){
A[k] = 0;
B[k] = 0;
}
k = 0; //Reset value of k to 0
//Take values for set A, this loop reads the numbers on the file correctly
while(A[k] != (-1)) {
fscanf(ifp, "%d", &A[k]);
k++;
}
k = 0; //Reset value of k to 0
//Take values for set B, no longer reads values from the file, I confirmed that the loop actually works.
while(B[k] != (-1)) {
fscanf(ifp, "%d", &B[k]);
k++;
}
Reading from the file
3 2 1 5 4 -1
5 8 4 -1
A[] will be 3 2 1 5 4,
but B[] will be 0 0 0 0...