I'm trying to have this pull numbers from a file put them in an array and then read out the smallest number. Right now it compiles but it prints out "Segmentation fault".
Any ideas what I'm not doing?
#include<iostream>
#include<fstream>
#include<cstdlib>
usingnamespace std;
main() {
cout << "I will pull the numbers from test.txt. put them in an array, and then print the smallest number. \n";
ifstream instream;
int file_numbers[100]; // name of the array
instream.open("test.txt");
if (instream.fail()) {
cout << "Faild to open file! \n";
exit(1);
}
while (instream >> file_numbers[100]); // <<< ????read from file to my array??????
int smallest;
for ( int i=1; i < file_numbers[100]; ++i )
if ( file_numbers[i] < smallest )
int smallest = file_numbers[i] ;
cout <<"" << smallest << '\n' ;
}