Why might I be getting the first line of my cout (Index Value) and then the message Segmentation fault? The file I am accessing reads out just fine. Thanks
void printArray(const int array[], int numElements);
// function to print the contents of the array
int main()
{
int aArray[SIZE] = {0};
ifstream inFile;
int index = 0;
const int num = 0;
inFile.open("random2.txt");
// read each integer from the txt file into current array
while (index < SIZE && inFile >> aArray[index])
index++;
// assign num to the value of each array subindex:
aArray[index] = num;
//close the file
inFile.close();
// call the function to print the file with 150 characters
// neatly displayed with a column indicating indices as well
// as the integers
printArray(num, SIZE);
return 0;
}
// Functions:
// function to print two columns, one for the index number, the other for
// the value of each array subindex
void printArray(const int array[], int numElements)
{
// establish printing spaces
const int INDEX_COL = 5;
const int VAL_COL = 8;
cout << "Index " <<" " << "Value" << endl;
cout << "----- -----" << endl;
for (int i = 0; i < numElements; i++){
cout << setw(INDEX_COL) << i << setw(VAL_COL) << array[i] << endl;
}
}