The argument "inputFile" is not needed, the variable is global and can be accessed by the function already.
In line 23, the argument for "num" (int& num) gives the function the variable by reference, meaning the actual variable in int main will change along with the one in the function. However, in line 36, you don't do that (int num). You seem to want to though, because you set "num" equal to count on line 52, but that change doesn't occur to the actual variable outside of that function.
but i don't know how to pass in data file into an array in one function and then print the array in another |
Your "readStoreFile" function seems fine, but if something is wrong with the way you "fin" input, I wouldn't know since I don't know what the .txt looks like or how you're wanting to use the information. Otherwise though, it seems alright.
Your printArr function is what's troubling. I assume you want this function to print out the contents of the array? You don't need ifstream at all for that. All you're doing right now is reopening the file and outputting the information that was in it, you're NOT outputting the data as saved in your array in the previous function.
To output your array, do something like this:
1 2 3 4
|
for(int i = 0; i < 10; i++)
{
std::cout << arr[i] << ' ';
}
|
And again, on line 58, you don't need to give arr as an argument, it already has access to that array since it was declared in the global scope.