Hello, I'm trying to move the integers in a file to an array and order them. I'm almost positive that I can order them using a sorting method. However, I'm having trouble getting the integers from the file into the array. I'm calling a function, int function(char* file, int* array), and passing argv[1] for the file and the array name (let's use array for the name). Then I fp=fopen(file, "r").
So, should I be using fscanf or getc to read in the integers from the file? The integers in the file are listed as such:
1
2
5
7
etc...
This is what I currently have for this section of code: (stop is initially 1 and i is initially 0)
If possible please do not just give the corrections; lead me in the direction that I need to go so that I may learn what I'm doing wrong.Code:do{ fscanf(fp, "%d", &num); /* am I using fscanf correctly? */ if(num == EOF){ stop = 0; } else a[i] = num; i++; read++; } while(stop);
Thank you for the help in advanced.