hi,
i want to know why i get "segmentation fault" when i try to run exe file in linux using './' command after compiling using g++ command .what is the problem??
hi,
i want to know why i get "segmentation fault" when i try to run exe file in linux using './' command after compiling using g++ command .what is the problem??
"If knowledge can create problems, it is not through ignorance that we can solve them. "
-Isaac Asimov(1920-1992)
I believe it gives you that error because there is a problem with memory in your program. Either allocating, or check your boundaries of your arrays, you may have gone over the limit of the array size somewhere.
-MethodMan-
Your Move:Life is a game, Play it; Life is a challenge, Meet it; Life is an opportunity, capture it.
Homepage: http://www.freewebs.com/andy_moog/home.html
thanx.
heres the code.Now wheres the fault ?? PLease let me know.
Code:struct iode { char* name ; }; int main(void) { iode* ptr; cin >> ptr->name ; }
name is a pointer that is uninitialised. You can either change it to be an array, or use dynamic memory allocation. Your choice
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
hi,
thanx for that but anywayz you say the name isnt initialized. how? its already initialised as pointer to char inside the struct.
thanx again dude.Code:struct iode { char* name ; // do you want me to initialise it as char* name[] ?? }; int main(void) { // now here i declare the object iode* ptr ; // and i access name cin>> ptr->name; // do you mean to say i do // ptr = new[] char* ??? or what?? }
"If knowledge can create problems, it is not through ignorance that we can solve them. "
-Isaac Asimov(1920-1992)
>>its already initialised
No, it's not.
>>as pointer to char inside the struct.
Thats what type of pointer it is. To initialise it, you must point it at a specific memory location.
You could change your struct entry to have name like this:
>>char name[100];
That is the simplest route. It gives you an array of 100 bytes to store the name.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]