K
kazik.lakomy
Hi,
could you help me with this stuff, it compiles fine, but when starting
the program there is segmentation fault. I enclose a message from
debugger:
----------
Program received signal SIGSEGV, Segmentation fault.
0x0000000000400ce0 in ReadInitialConditions (TabX=0x7fffb62f1880,
TabY=0x7fffb62f1480, TableSize=128, InitCondFile=@0x7fffb62f1c80)
at readprog.cpp:9
9 while(! InitCondFile.eof() ){
----------
This is the code:
#include <iostream>
#include <fstream>
using namespace std;
void ReadInitialConditions(double* TabX, double* TabY, int TableSize,
ifstream & InitCondFile){
int XorYCounter = 0;
int XYPairsCounter = 0;
if(InitCondFile.is_open()){
while(! InitCondFile.eof() ){
double num;
InitCondFile>>num;
if((XorYCounter % 2) == 0)
TabX[XYPairsCounter] = num;
if((XorYCounter % 2) != 0){
TabY[XYPairsCounter] = num;
XYPairsCounter++;
}
XorYCounter++;
}
InitCondFile.close();
}
else
cout<<"Unable to open file";
}
int main(){
ifstream InitCondFile("groundsol.dat");
const int TableSize = 128;
double TabX[TableSize];
double TabY[TableSize];
ReadInitialConditions(TabX, TabY, TableSize, InitCondFile);
for(int j=0; j<TableSize; j++)
cout<<"x"<<j<<": "<<TabX[j]<<" y"<<j<<": "<<TabY[j]<<endl;
return 0;
}
could you help me with this stuff, it compiles fine, but when starting
the program there is segmentation fault. I enclose a message from
debugger:
----------
Program received signal SIGSEGV, Segmentation fault.
0x0000000000400ce0 in ReadInitialConditions (TabX=0x7fffb62f1880,
TabY=0x7fffb62f1480, TableSize=128, InitCondFile=@0x7fffb62f1c80)
at readprog.cpp:9
9 while(! InitCondFile.eof() ){
----------
This is the code:
#include <iostream>
#include <fstream>
using namespace std;
void ReadInitialConditions(double* TabX, double* TabY, int TableSize,
ifstream & InitCondFile){
int XorYCounter = 0;
int XYPairsCounter = 0;
if(InitCondFile.is_open()){
while(! InitCondFile.eof() ){
double num;
InitCondFile>>num;
if((XorYCounter % 2) == 0)
TabX[XYPairsCounter] = num;
if((XorYCounter % 2) != 0){
TabY[XYPairsCounter] = num;
XYPairsCounter++;
}
XorYCounter++;
}
InitCondFile.close();
}
else
cout<<"Unable to open file";
}
int main(){
ifstream InitCondFile("groundsol.dat");
const int TableSize = 128;
double TabX[TableSize];
double TabY[TableSize];
ReadInitialConditions(TabX, TabY, TableSize, InitCondFile);
for(int j=0; j<TableSize; j++)
cout<<"x"<<j<<": "<<TabX[j]<<" y"<<j<<": "<<TabY[j]<<endl;
return 0;
}