Input/output file with arrays

Hi, I'm not understanding where I went wrong here. It compiles fine, but then my file doesn't have the array numbers and gives a stack overflow warning. Can anyone tell me where I went wrong?

#include <iostream>
#include <fstream>
using namespace std;


const int NUM_ARRAY = 20;
void file(double[]);
void secondFile(double[]);

int main()
{
double numArray[NUM_ARRAY] = { 88, 85, 89, 64, 78, 85, 92, 60, 91, 96, 63, 59, 83, 89, 74, 93, 92, 92, 63, 100 };
double secondArray[NUM_ARRAY];

file(numArray);

secondFile(secondArray);

system("pause");
return 0;
}
void file(double numArray[])
{
ofstream myFirstFile;
int x = 0;

myFirstFile.open("final.txt");

if (!myFirstFile)
cout << "Error opening the file." << endl;
else
{
cout << "Writing to a file." << endl;

for (x; x < NUM_ARRAY; x++);
{
myFirstFile << numArray[x];
}

myFirstFile.close();
}

system("Pause");
}
void secondFile(double secondArray[])
{
ifstream myFirstFile;
int x;
myFirstFile.open("final.txt");

if (!myFirstFile)
cout << "Error opening the file." << endl;
else
{
cout << "Writing from a file." << endl;

for (x = 0; x < NUM_ARRAY; x++);
{
myFirstFile >> secondArray[x];
}

myFirstFile.close();
}

system("Pause");
}
> and gives a stack overflow warning
¿? stack overflow is a fatal error.
I did not observe such behaviour, and don't see anything in the code that may cause it.

However
$ g++ -W{all,extra,pedantic} foo.cpp
foo.cpp: In function ‘void file(double*)’:
foo.cpp:36:9: warning: statement has no effect [-Wunused-value]
		for (x; x < NUM_ARRAY; x++);
¿see the semicolon at the end? that was your loop executes
(you would have no issue if you had limited the scope of the variable)
Topic archived. No new replies allowed.