Segmentation fault

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

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

const int SIZE = 150;

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;
}
}
closed account (zb0S216C)
Look at printArray()'s invocation. num isn't an array, it's a constant integer.

Wazzak
Ah yes! Thanks ..I got rid of const int num, and its assignment, and called for
printArray(aArray,SIZE); and it worked like a charm. Total beauty.
Topic archived. No new replies allowed.