Hi!. I am having some problems with functions scopes again. I need to use one array initialized in one function, in a different function. I have searched on how to pass the array by reference or value ( and I truly don't know if that's what I need) but I really don't understand it.
This is only part of my code. If you need the rest I will post it:
#include <iostream>
#include <fstream>
#include <string>
#include "Savedata.h"
using namespace std;
void outputSavedata (int stats[4])
{
cout<< "\nStrengh:" << stats[0] << "\n";
cout<< "Defense:" << stats[1] << "\n";
cout<< "Hitpoints:" << stats[2] << "\n";
cout<< "Experience:" << stats[3] << "\n";
cout<< "Level:" << stats[4] << "\n";
}
void retreiveSavedata (string filename)
{
int stats[4];
ifstream file(filename.c_str());
string skipline;
getline(file, skipline);
file>> stats[0];
file>> stats[1];
file>> stats[2];
file>> stats[3];
file>> stats[4];
outputSavedata(stats);
file.close();
}
As you can see I need to use the stats[4] array in the retrieveSavedata function in the outputSavedata function. But when I try to initializeit, it gives me this error:
'stats' not declared in that scope
Any help is appreciated,
AssaultM16