C++ Program, Segmentation Fault
My c++ program keeps giving me a segmentation fault error. I believe the error is in the way i call my main function.
./program.exe student.data name Nelson is how i call it and int main(int argc, char *argv[]) { //program code } is the definition in main. Note that the first line in main is a cout statement which does not execute, meaning that the error is somewhere before it. The program is a C++ program that takes in values (above) and returns them to a CGI script. Thanks. Josh |
There's nothing wrong with the way you run the program. It may be something wrong (and probably is if it's the first line) with the cout. Remember that if cout crashes, it doesn't print the text.
How does the cout line look like? |
A segmentation fault is cause by referencing a pointer that has not been properly set. I'm sure that you are getting into your program. The cout may not display becasue you've not put a new line in the cout. Probably what is happing is that the output is sent to cout but it is sitting there waiting for a new line before it displays, then along comes your segmentation fault and everything goes pear shaped :(
Fist make sure that you have requested a new line. YOu can do this is follows: Code:
std::cout << "Hello \n"; graeme. |
the line looks like
cout << "Got here." << endl; |
the line looks like
cout << "Got here." << endl; it is one of the lines i used to find where the segmentation fault was. (sorry firefox messed up and i posted twice by accident) |
I know these are going to sound like a silly questions but let's get them out of the way first.
|
whoops
Nevermind, i forgot to recompile after I modified my code last time, after I added some functions. My (very stupid) mistake. Thanks to everyone for your help.
|
All times are GMT -5. The time now is 07:33 AM. |