Data organization

I am trying to input a file to an array and then seperate the file based on order, there are 8 output files.
My problem is that all the values end up taking around 18.6e19 for their value. I checked the base file and it is fine Thank you

#include <iostream>
#include <fstream>
#define MAX 29656
using namespace std;
long long unsigned el[MAX];
fstream file1("results.txt");
ofstream file2("Energy1.txt");
ofstream file3("Px1.txt");
ofstream file4("Py1.txt");
ofstream file5("Px1.txt");
//file5.open("Pz1.txt");
ofstream file6("Energy2.txt");
//file6.open("Energy2.txt");
ofstream file7("Px2.txt");
ofstream file8("Py2.txt");
//file8.open("Py2.txt");
ofstream file9("Pz2.txt");
//file9.open("Pz2.txt");
void input()
{
for (int n=1; n<=MAX; n++)
{
el[n]=file1.get();
}
}
void output()
{
for (long long i=1; i<=MAX; i++)
{
int j=i%8;
if (j==1)
{
//ofstream file2;
// file2.open("Energy1.txt");
float E1= el[i];
file2 <<E1 <<endl;
//file2.close();
}
if (j==2)
{
//ofstream file3;
// file3.open("Px1.txt");
float Px1= el[i];
file3 <<Px1 <<endl;
//file3.close();
}
if (j==3)
{
//ofstream file4;
//file4.open("Py1.txt");
float Py1= el[i];
file4 <<Py1 <<endl;
// file4.close();
}
if (j==4)
{
// ofstream file5("Px1.txt");
// file5.open("Pz1.txt");
float Pz1= el[i];
file5 <<Pz1 <<endl;
//file5.close();
}
if (j==5)
{
//ofstream file6("Energy2.txt");
//file6.open("Energy2.txt");
float E2= el[i];
file6 <<E2 <<endl;
// file6.close();
}
if (j==6)
{
//ofstream file7("Px2.txt");
//file7.open("Px2.txt");
float Px2= el[i];
file7 <<Px2 <<endl;
// file7.close();
}

if (j==7)
{
//ofstream file8("Py2.txt");
//file8.open("Py2.txt");
float Py2=el[i];
file8 <<Py2 <<endl;
//file8.close();
}
if (j==0)
{
//ofstream file9("Pz2.txt");
// file9.open("Pz2.txt");
float Pz2=el[i];
file9 <<Pz2 <<endl;
// file9.close();
}

}
}
int main()
{
input();
for(int l=200;l<210;l++)
{
cout<<el[l]<<endl;
}
output();
file2.close();
file3.close();
file4.close();
file5.close();
file6.close();
file7.close();
file8.close();
file9.close();
return 0;
}
Last edited on
Where are you checking (a) that the file is opened successfully and (b) that each input operation is successful?

thought that el[l]would be a sufficinet check, but it was not
new addition to code,
add a if(file1.eof0{ main}
else {return 0;}
file is not opening
also added a cout <<j to every input stack
Last edited on
might the error in opening come from an improperly addressed pointer to the file?
Topic archived. No new replies allowed.