Hy try this.
#include
#define MAX_NUMBERS 1000 /* Max numbers in file */
const char DATA_FILE[] = "numbers.dat"; /* File with numbers */
int data[MAX_NUMBERS]; /* Array of numbers */
int main()
{
FILE *in_file; /* Input file */
int middle; /* Middle of our search range */
int low, high; /* Upper/lower bound */
int search; /* number to search for */
char line[80]; /* Input line */
in_file = fopen(DATA_FILE, "r");
if (in_file == NULL) {
fprintf(stderr,"Error:Unable to open %s\n", DATA_FILE);
exit (8);
}
/*
* Read in data
*/
max_count = 0;
while (1) {
if (fgets(line, sizeof(line), in_file) == NULL)
break;
/* convert number */
sscanf(line, "%d", &data[max_count]);
++max_count;
return data;
}
return (0);
}