csripriya1
Programmer
Hi all,
I have a problem with this access violation.A function in my class reads in
a bunch of values.My program crashes towards the end of this function.It prints
NINFOLINE correctly ,waits for the input(test) then dies after taking the input
for test.When it crashes,it gives an error message of access violation.I am wondering
what would have gone wrong in the end?
The program crashed for few input files ,but worked fine for other input files.
In both the cases the last line INFOLINE was printed and the input for test was taken.
I have given my code below.Can anyone help me in this regard.Thanks for your time.
#include "sdf_class.h"
void sdfcomp::getData(char *stra)
{
char dummy[80];
char *chk=NULL;
int in;
int test;
ifstream inpfile(stra,ios::in);
if(!inpfile)
{
cerr<<"File could not be opened"<<endl;
exit(1);
}
inpfile>>natoms;
xcrd=new float[natoms];
ycrd=new float[natoms];
zcrd=new float[natoms];
assert(xcrd!=0);
assert(ycrd!=0);
assert(zcrd!=0);
in=1;
while(in<=natoms)
{
inpfile>>xcrd[in]>>ycrd[in]>>zcrd[in];
in++;
}
in=0;
chk="$$$$";
inpfile.getline(dummy,80,'\n');
while(strcmp(dummy,chk)!=0 )
{
cout<<"string tbc:"<<dummy<<endl;
strcpy(dum[in],dummy);
inpfile.getline(dummy,80,'\n');
in ++;
}
ninfoline=in;
cout<<"NINFOLINE:"<<in<<endl;
cin>>test;
}
I have a problem with this access violation.A function in my class reads in
a bunch of values.My program crashes towards the end of this function.It prints
NINFOLINE correctly ,waits for the input(test) then dies after taking the input
for test.When it crashes,it gives an error message of access violation.I am wondering
what would have gone wrong in the end?
The program crashed for few input files ,but worked fine for other input files.
In both the cases the last line INFOLINE was printed and the input for test was taken.
I have given my code below.Can anyone help me in this regard.Thanks for your time.
#include "sdf_class.h"
void sdfcomp::getData(char *stra)
{
char dummy[80];
char *chk=NULL;
int in;
int test;
ifstream inpfile(stra,ios::in);
if(!inpfile)
{
cerr<<"File could not be opened"<<endl;
exit(1);
}
inpfile>>natoms;
xcrd=new float[natoms];
ycrd=new float[natoms];
zcrd=new float[natoms];
assert(xcrd!=0);
assert(ycrd!=0);
assert(zcrd!=0);
in=1;
while(in<=natoms)
{
inpfile>>xcrd[in]>>ycrd[in]>>zcrd[in];
in++;
}
in=0;
chk="$$$$";
inpfile.getline(dummy,80,'\n');
while(strcmp(dummy,chk)!=0 )
{
cout<<"string tbc:"<<dummy<<endl;
strcpy(dum[in],dummy);
inpfile.getline(dummy,80,'\n');
in ++;
}
ninfoline=in;
cout<<"NINFOLINE:"<<in<<endl;
cin>>test;
}