This cannot succeed...
Code:
// Cut 1: Prototypes...
int Config (int check, int firstrun); Param passed as VALUE. References are denotated with &
int Config2 (string line, int firstrun);
// Cut 2: main()...
int main()
{
int check;
int firstrun;
Config(check,firstrun); params passed as if they were references.
//(check and firstrun now still uninitialized, containing random data)
if (check == 1 && firstrun == 1)//both variables contain random data, The result of this check is random as well
{
ofstream config;
config.open ("firstruncheck.sece", ios::out);
config << "false";
config.close();
ofstream autoexec;
autoexec.open ("autoexec.cfg", ios::out | ios::app);
autoexec << "// SECE execution commands...\n";
autoexec.close();
// needs a return code. 'return 0'
}
else
{
cout << "The program seems to have returned an error...\n";
// needs a return code. 'return 1'
}
// Main lacks an ending } here. Keeps code seperated as obviously intended, without subfunctions.
// Cut 3: Functions...
int Config (int check, int firstrun)
{
string line;
ifstream config ("firstruncheck.sece");
if (config.is_open())
{
while (!config.eof())
{
getline (config,line);
Config2(line,firstrun);// calling this has no effect. firstrun is passed as value, not as reference. try a statement like 'firstrun = Config2(line);' after modifying the code
continue;//not needed at the end of a loop
}
check = 1; // check is a local parameter, not a reference. initialize will affect nothing here.
return (check,firstrun);// not valid. return code must be an int type. like 0
}
else
{
cout << "The program has returned an error...\n";
cout << "Please try again...\n";
main();//restarts main(), evokes an endless loop of calls. Should be 'return 1'
}
}
// Function 2...
int Config2 (string line, int firstrun)
{
if (line == "true")
{
firstrun = 1;
}
return (firstrun);
}
[/quote]
I didnt check the functions for validity, there can be more errors.
Good Luck
