getting Segmentation error working with arrays

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?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  #include<iostream>
#include<fstream>
#include<cstdlib>

using namespace 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' ;
}
This statement

while (instream >> file_numbers[100]);

is invalid. First of all the array has no the element with the index equal to 100. Secondly the statement has no any sense


Try the following

1
2
3
4
5
6
const size_t N = 100;
int file_numbers[N];

size_t i = 0;

while ( i < N && instream >> file_numbers[i]) i++;     
By the way this code

1
2
3
4
5
   int smallest;
    for ( int i=1;  i < file_numbers[100];  ++i )

        if ( file_numbers[i] < smallest )
             int smallest = file_numbers[i] ;


is also invalid and has no sense.
Okay thank you very much.
Topic archived. No new replies allowed.