Unhandled exception...
-
ok... I've had problems with unhandled exception error before... but right when i fixed it, i kind of forgot what i did to fix it... this is my code... "im posting it all.. except my header file, just to make sure you know what im doing." #include #include "Class.h"//included header "Class.h" using namespace std; Name person; //class def person int NN = 1;//incriment char Names[21]; //total amount of names char SName[100]; //SetName function. bool Name::SetName(char* NName) { if(!NName) { return false; } int NLen = (strlen(NName) + 1); char *NewName = new char[NLen]; if(!NewName) { return false; } strcpy(NewName, NName); delete[] M_Name; M_Name = NewName; Names[NN] = *M_Name;//I think it has somthing to do with this NN++; return true; } const char* Name::GetName() { return M_Name; } //main int main() { for(;;)//main loop { gets(SName); person.SetName(SName); cout << person.GetName() << endl << endl; //print name that you just typed. for(int inc;inc < NN;inc++) //print all names. { cout << Names[inc] << endl; //error unhandled exception. }//end of print all names, loop. inc = 1; }//end main loop. return 0; } //end main //constructor & deconstructor //******************* Name::Name() { M_Name = NULL; } Name::~Name() { delete[] M_Name; } The error accured when i tried to set Names[NN] = *M_Name; the error feels like its at the tip of my tongue, yet i cant think of it. Thanks all for the help! ~SilverShalkin ps... how do you show a screen shot of your code? or post your code on CP with its background different... "is ther a place on the forum that shows how?" Thanks! :rose:
-
ok... I've had problems with unhandled exception error before... but right when i fixed it, i kind of forgot what i did to fix it... this is my code... "im posting it all.. except my header file, just to make sure you know what im doing." #include #include "Class.h"//included header "Class.h" using namespace std; Name person; //class def person int NN = 1;//incriment char Names[21]; //total amount of names char SName[100]; //SetName function. bool Name::SetName(char* NName) { if(!NName) { return false; } int NLen = (strlen(NName) + 1); char *NewName = new char[NLen]; if(!NewName) { return false; } strcpy(NewName, NName); delete[] M_Name; M_Name = NewName; Names[NN] = *M_Name;//I think it has somthing to do with this NN++; return true; } const char* Name::GetName() { return M_Name; } //main int main() { for(;;)//main loop { gets(SName); person.SetName(SName); cout << person.GetName() << endl << endl; //print name that you just typed. for(int inc;inc < NN;inc++) //print all names. { cout << Names[inc] << endl; //error unhandled exception. }//end of print all names, loop. inc = 1; }//end main loop. return 0; } //end main //constructor & deconstructor //******************* Name::Name() { M_Name = NULL; } Name::~Name() { delete[] M_Name; } The error accured when i tried to set Names[NN] = *M_Name; the error feels like its at the tip of my tongue, yet i cant think of it. Thanks all for the help! ~SilverShalkin ps... how do you show a screen shot of your code? or post your code on CP with its background different... "is ther a place on the forum that shows how?" Thanks! :rose:
-
ok... I've had problems with unhandled exception error before... but right when i fixed it, i kind of forgot what i did to fix it... this is my code... "im posting it all.. except my header file, just to make sure you know what im doing." #include #include "Class.h"//included header "Class.h" using namespace std; Name person; //class def person int NN = 1;//incriment char Names[21]; //total amount of names char SName[100]; //SetName function. bool Name::SetName(char* NName) { if(!NName) { return false; } int NLen = (strlen(NName) + 1); char *NewName = new char[NLen]; if(!NewName) { return false; } strcpy(NewName, NName); delete[] M_Name; M_Name = NewName; Names[NN] = *M_Name;//I think it has somthing to do with this NN++; return true; } const char* Name::GetName() { return M_Name; } //main int main() { for(;;)//main loop { gets(SName); person.SetName(SName); cout << person.GetName() << endl << endl; //print name that you just typed. for(int inc;inc < NN;inc++) //print all names. { cout << Names[inc] << endl; //error unhandled exception. }//end of print all names, loop. inc = 1; }//end main loop. return 0; } //end main //constructor & deconstructor //******************* Name::Name() { M_Name = NULL; } Name::~Name() { delete[] M_Name; } The error accured when i tried to set Names[NN] = *M_Name; the error feels like its at the tip of my tongue, yet i cant think of it. Thanks all for the help! ~SilverShalkin ps... how do you show a screen shot of your code? or post your code on CP with its background different... "is ther a place on the forum that shows how?" Thanks! :rose:
M_Name is probably NULL and you're trying to deference it. You can make your code look different by wrapping it in a <pre> tag, but of course then you need to type & lt and & gt ( without the space ) to get your < > characters. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
-
I didn't even look through the code, but that is truly awesome. SilverShakin - step into the debugger sometime to see what amazingly huge negative numbers an unassigned int gets as a default value. One thing I like about C# - it sets sensible default values for variables. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
-
M_Name is probably NULL and you're trying to deference it. You can make your code look different by wrapping it in a <pre> tag, but of course then you need to type & lt and & gt ( without the space ) to get your < > characters. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
int the for loop the for(int inc; the int initializes, or defines inc as an intiger... therefore i do not need to define it anywhere else... but ill look over it and see if i made a mistake... Thanks all! M_Name is = NULL,.... hmm im thinking... ill go and change some things... if i cant figuere it out, ill jump back on Thanks again! ~SilverShalkin :rose:
-
int the for loop the for(int inc; the int initializes, or defines inc as an intiger... therefore i do not need to define it anywhere else... but ill look over it and see if i made a mistake... Thanks all! M_Name is = NULL,.... hmm im thinking... ill go and change some things... if i cant figuere it out, ill jump back on Thanks again! ~SilverShalkin :rose:
The problem is exactly as has been stated - you define an integer, but do not give it a value. It's value will be in the order of -80,0000. You need to put int inc = 0, not just int inc. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
-
int the for loop the for(int inc; the int initializes, or defines inc as an intiger... therefore i do not need to define it anywhere else... but ill look over it and see if i made a mistake... Thanks all! M_Name is = NULL,.... hmm im thinking... ill go and change some things... if i cant figuere it out, ill jump back on Thanks again! ~SilverShalkin :rose:
ok, ok... i thought you ment that i had to int inc... and i responded by that i have already... but i got the main point... i changed the for n loop to: for(int inc = 0;inc < NN;inc++) and it worked.. thanks! But i still have the problem with the unhandled... i didnt have time to change some things but, ill keep your responses in mind :) thanks for the help all! ~SilverShalkin :rose:
-
ok... I've had problems with unhandled exception error before... but right when i fixed it, i kind of forgot what i did to fix it... this is my code... "im posting it all.. except my header file, just to make sure you know what im doing." #include #include "Class.h"//included header "Class.h" using namespace std; Name person; //class def person int NN = 1;//incriment char Names[21]; //total amount of names char SName[100]; //SetName function. bool Name::SetName(char* NName) { if(!NName) { return false; } int NLen = (strlen(NName) + 1); char *NewName = new char[NLen]; if(!NewName) { return false; } strcpy(NewName, NName); delete[] M_Name; M_Name = NewName; Names[NN] = *M_Name;//I think it has somthing to do with this NN++; return true; } const char* Name::GetName() { return M_Name; } //main int main() { for(;;)//main loop { gets(SName); person.SetName(SName); cout << person.GetName() << endl << endl; //print name that you just typed. for(int inc;inc < NN;inc++) //print all names. { cout << Names[inc] << endl; //error unhandled exception. }//end of print all names, loop. inc = 1; }//end main loop. return 0; } //end main //constructor & deconstructor //******************* Name::Name() { M_Name = NULL; } Name::~Name() { delete[] M_Name; } The error accured when i tried to set Names[NN] = *M_Name; the error feels like its at the tip of my tongue, yet i cant think of it. Thanks all for the help! ~SilverShalkin ps... how do you show a screen shot of your code? or post your code on CP with its background different... "is ther a place on the forum that shows how?" Thanks! :rose:
please initialise the Loop Running variable mnc in to zero.. ie you must for(int mnc=0;mnc
-
ok, ok... i thought you ment that i had to int inc... and i responded by that i have already... but i got the main point... i changed the for n loop to: for(int inc = 0;inc < NN;inc++) and it worked.. thanks! But i still have the problem with the unhandled... i didnt have time to change some things but, ill keep your responses in mind :) thanks for the help all! ~SilverShalkin :rose:
Have you traced to see if your variable being referenced is NULL, or added a check to alert you to this case ? Checking if a variable is valid is always good - initialise all pointers to NULL, check if they are NULL before dereferencing or calling methods on them. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
-
please initialise the Loop Running variable mnc in to zero.. ie you must for(int mnc=0;mnc
i did set it = to zero,... for the most part, that fixed it :) Thanks! ~SilverShalkin ps... I'll work the debugger on the NULL pointers :) Thanks! :rose: