void fillarray(int x, int []);
void displayarray(int m, int []);
void sortarray(int p, int []);
int main()
{
int myarray[10];
int usersize;
cout << "Enter an integer less than 10: ";
cin >> usersize;
fillarray(usersize, myarray);
displayarray(usersize, myarray);
sortarray(usersize, myarray);
displayarray(usersize, myarray);
}
void fillarray(int x, int file[])
{ int i = 0;
for(i; i < x; i++)
{ file[i] = i;}
}
void displayarray(int m, int file[])
{ int j = 0;
for (j; j < m; j++)
{ cout << file[j] << " ";}
cout << endl;
}
void sortarray(int p, int file[])
{ int y = 0, z = 0, temp = 0;
for(y; y < (p - 1); y++)
{
for(z = y + 1; z < p; z++)
{ temp = file[y];
file[y] = file[z];
file[z] = temp;
}
}
}
My code is the code above. The main point of the program is to see how the program will react when you fill and display the array even though you went past the declared size. I'm having trouble with filling and printing the array. I need to use a usersize of 5, 25, 100, 1000, and 1000000 to show segmentation faults. Please help.