Well, the stringstream is a bit of an overkill for this task. In its current form, it does more harm than good, as only the very first number from each line is processed.
However, that's a relatively small problem.There are other issues. The array declarations give a compiler error, a zero-size array is not permitted.
Try changing this:
1 2 3
|
int evenArray[] = {};
int oddArray[] = {};
int array[] = {};
|
to something like this:
1 2 3
|
int evenArray[100] = {0};
int oddArray[100] = {0};
int array[100] = {0};
|
Here I've declared each array can hold 100 elements and initialised the contents with zeros.
Inside the function oddOrEven()
1 2 3 4
|
if (array[i] % 2 == 0) {
evenArray[i] = array[i];
a++;
}
|
the incorrect subscript is used when storing the values.
It should be:
1 2 3 4
|
if (array[i] % 2 == 0) {
evenArray[a] = array[i];
a++;
}
|
and the same applies to the other array, where
b should be used in place of
i.
That still leaves the stringstream. Either remove it completely (recommended) and just do
fileIn >> array[i]
rather than getline(). Or if you want to practice using stringstreams, add an inner loop to process the stringstream in this manner, just as though it was a file.