unhandaled exception,0X000005:access violation

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2004
Posts: 1
Reputation: michal is an unknown quantity at this point 
Solved Threads: 0
michal michal is offline Offline
Newbie Poster

unhandaled exception,0X000005:access violation

 
0
  #1
Oct 9th, 2004
Hi,
I get this message when the program shold exit the main function. I think that the problam could be in that function (that is being called from main):
void scanFileToMat( ifstream mFile,int arr[43][43])
{
string m ,s;
int pos;
double sign;
int col, value;
getline(mFile,m,')');
while(!mFile.eof())
{

mFile>>sign;
arr[numSV][42]=sign>0;
getline(mFile,m,'\n');

while(m.length())


{ pos=m.find_first_of(':');
s=m.substr(0,pos);
char *charArr=new char[pos+1];
for(int i=0;i<pos;i++)
charArr[i]=s[i];
col=atoi(charArr);
delete []charArr;
m=m.substr(pos+1);
pos=m.find_first_of(' ');
s=m.substr(0,pos);
char *charArr2=new char[pos+1];
for(i=0;i<pos;i++)
charArr2[i]=s[i];
value=atoi(charArr2);
delete []charArr2;
m=m.substr(pos+1);

arr[numSV][col]=value;
}



numSV++;
}

return;
}
But I cant see where!
Any help will make me happy

Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,847
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 753
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Senior Bitch

Re: unhandaled exception,0X000005:access violation

 
0
  #2
Oct 9th, 2004
>But I cant see where!
That's because you're doing so much that could cause it! An access violation is when you access memory outside of your address space. This is most often caused by writing to uninitialized memory (through a pointer) or by overrunning the boundaries of an array (either statically or dynamically allocated).

If you don't have a good debugger, litter your code with debug statements that tell you exactly what the limits of your arrays are and what the values of the indices you're using are. Then print the value of your pointers to ensure that they're pointed where you want them to be, and pay careful attention to your dynamic allocation. An off-by-one error there will usually show up when the memory is reclaimed. The memory manager is a fragile beast and you must be especially careful.
New members chased away this month: 4
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC