text: #include <stdio.h> #define NOT_FOUND -1 int search( const int arr[], int target, int n); int main(void) { int x[13]; int index; int target; FILE* data_in; data_in=fopen("data.txt", "r"); fscanf(data_in , "%d" , &x[13] ); printf("%d\n", x[1]); //test to see if scan from data.txt is successful printf("Please enter a value (-1 = done)> "); scanf("%d", &target); index = search( x, target, 10); if (index == NOT_FOUND ) printf("%d is not in the array.\n", target); else printf("%d is located at position %d in the array.\n", target, index); return(0); }
  My search function works fine. Any ideas on how to scan that file data into my array would be appreciated. I'd like my output to look like...
  $ ./binary.out
  Array before sort = 12 7 8 17 2 20 19 16 14 3 2 1
  Array after sort = 1 2 2 3 7 8 12 14 16 17 19 20
  Please enter a value (-1 = done)> 3
  3 is located at position 3 in the array.
  Please enter a value (-1 = done)> 14
  14 is located at position 7 in the array.