I am currenty writing a program that needs to read in an unknown number of integers from a file and sort them using selection sort (with a max 100,000 integers). Here is my code so far:

Code:

#include <stdio.h>
void selectionsort ( int x[], int size ) ;
int main ( int argc, char *argv[] ) {
int x[100000], i ;
FILE *fin = fopen ( argv [1], "r" ) ;
for ( i = 0 ; i < 100000 ; i++ ) {
fscanf ( fin, "%d", &x[i] ) ;
}
selectionsort ( x, i ) ;
printf ( "\nThe first five sorted numbers are: %d %d %d %d %d\n", x[0], x[1], x[2], x[3], x[4] ) ;
printf ( "The last five sorted numbers are: %d %d %d %d %d\n\n", x[i-5], x[i-4], x[i-3], x[i-2], x[i-1] ) ;
fclose ( fin ) ;
return 0 ;
}
void selectionsort ( int x[], int size ) {
int i, j, min_index, temp ;
for ( i = 0 ; i < size - 1 ; i++ ) {
min_index = i ;
for ( j = i + 1 ; j < size ; j++ ) {
if ( x[j] < x[min_index] ) min_index = j ;
}
temp = x[i];
x[i] = x[min_index] ;
x[min_index] = temp ;
}
}

Now my question is, how would I go about stopping the for-loop in main when fscanf starts scanning just blanks. I tried adding " if ( x[ i ] == ' ' ) break ; " after the fscanf but it doesn't work. What would I need to add so it stops scanning the file when it runs out of numbers?

Thank you very much