text: Hello everyone. I am having a problem with reading a textfile of ints into an array for sorting. The text file has the format of:
  My main function is:My main function is:Code:1 2 3 . . .
  The sort functions work correctly as I have tried them with a simple loop and array.The sort functions work correctly as I have tried them with a simple loop and array.Code:#include "header.h" int main(void) { int i, array[SIZE]; char buf[SIZE]; FILE *fp; fp = fopen("100_sorted.txt", "r"); if (fp ==NULL) { printf("Cannot open file for reading"); exit(EXIT_FAILURE); } fgets(buf, sizeof(buf), fp); for (i = 0; i < SIZE; i++){ sscanf(buf, "%d", &array[i]); } fclose(fp); insertion_sort(array,i); //selection_sort(array, n); //bubble_sort(array, n); //mod_bubble_sort(array, n); //quick_sort(array, 0, n - 1); //merge_sort(array, 0, n -1); for (i = 0; i < SIZE; i++){ printf("%d\n", array[i]); } return (EXIT_SUCCESS); }
  What is happening is it is seems to read the first int which is "1" and loops the "1" continously instead of reasing the next line.
  I know it is probably something rather simple but I have been at it for a few hours and need a fresh set of eyes to take a looksee.
  I would appreciate if someone could tell me what I need to do to fix it.
  Thanks!