I need to read text files into an array. The text files are formatted so that the first line contains the array size and the following lines are the elements of the array:
6
5
3
2
1
6
4
Where the array size equals 6. The files need to be read in this format:
a.exe < testfiles/input
Here's what I have so far:
int main(){
int arraySize = 0;
cin >> arraySize;
int array[arraySize];
for(i = 1; i < arraySize; i++){
cin >> array[i];
}
for(j = 0; j < arraySize-1; j++){
//insertion sort here
}
}
The array remains all zeros but is the correct size. Can anyone see my error?
EDIT: I've fixed the array to be dynamically allocated. The program now executes without an error, but now the entire array is full of the second entry of the text file, in this case, 5.