I need to have my program use a function to read in numbers from a file to an array, and pass the array back to my main program to be outputted/used by another function; however, I am getting an error(cannot convert from 'int' to 'int [100]'): Here is the relevant code I have so far:
#include<iostream>
#include<fstream>
using namespace std;
int readFile(int arg[]);
void main()
{
int numarray[100];
[b]numarray = readFile(numarray[])[/b]
}
int readFile(int nums[])
{
int x = 1;
fstream numfile("numbers.txt");
while(! numfile.eof() )
{
numfile >> nums[x];
x++;
}
return nums;
}
Note: Bolded line is where the compiler says the error is.
I initially tried to create the array inside the function, but read that passing it back wouldn't work, as I was passing back a reference to a local memory location only valid inside the function. So I tried creating the array in main, passing to the function, reading in, and returning it, but it still gives me the "cannot convert" error. How can I fix it so it doesn't give me this error?
I apologize if this has been answered before, but all the threads I read have confusing examples that don't seem to work in my application. Thanks in advance!