Teen Programmers Unite  
 

 

Return to forum top

C++ "Segmentation Fault"

Posted by 142857 [send private reply] at November 02, 2002, 01:04:58 PM

I am trying to run a tic-tac-toe program in Redhat Linux, and before, when I ran it with 1 predefined function in main, it was fine. But then, when I had it call another longer function in main, it ran the first function, but in place of the second function's output, it said "Segmentation fault". Do you know what the problem is? thanks

Posted by Psion [send private reply] at November 02, 2002, 01:39:01 PM

This is really a generic "your program is broken" error in C, since the language lets you screw yourself over in especially nasty ways. Look for cases of abusing pointers, passing bad arguments to system functions that might then be inspired to abuse pointers, etc..

Posted by 142857 [send private reply] at November 02, 2002, 02:57:42 PM

okay.

Posted by 142857 [send private reply] at November 02, 2002, 11:44:00 PM

yes. that's what happened. earlier in a function that was used in this function, i said:

int distanceBetweenPoints
{
int returner;
returner += ...;
returner ...;
returner returner;
}

And I never set returner to 0 at the beginning. So I realized that, set it to 0, and now it works. Thanks

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.