LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-07-2005, 04:05 PM   #1
Fireball7
Member
 
Registered: Nov 2005
Location: Lexington, Kentucky
Distribution: Slackware 10.2, Ubuntu 6.06
Posts: 46

Rep: Reputation: 15
Question 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

Last edited by Fireball7; 12-07-2005 at 04:07 PM.
 
Old 12-07-2005, 04:12 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,537

Rep: Reputation: 149Reputation: 149
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?
 
Old 12-07-2005, 04:15 PM   #3
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
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";
For us to really help you with the segmentation fault we need a little more to go on


graeme.
 
Old 12-07-2005, 04:16 PM   #4
Fireball7
Member
 
Registered: Nov 2005
Location: Lexington, Kentucky
Distribution: Slackware 10.2, Ubuntu 6.06
Posts: 46

Original Poster
Rep: Reputation: 15
the line looks like

cout << "Got here." << endl;
 
Old 12-07-2005, 04:16 PM   #5
Fireball7
Member
 
Registered: Nov 2005
Location: Lexington, Kentucky
Distribution: Slackware 10.2, Ubuntu 6.06
Posts: 46

Original Poster
Rep: Reputation: 15
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)

Last edited by Fireball7; 12-07-2005 at 04:17 PM.
 
Old 12-07-2005, 04:20 PM   #6
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
I know these are going to sound like a silly questions but let's get them out of the way first.
  • Did you re compile
  • Did it work
  • Did you link
  • Did it work
  • Are you sure? Check the time you program.exe was created
 
Old 12-07-2005, 04:22 PM   #7
Fireball7
Member
 
Registered: Nov 2005
Location: Lexington, Kentucky
Distribution: Slackware 10.2, Ubuntu 6.06
Posts: 46

Original Poster
Rep: Reputation: 15
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why segmentation fault in this program? asahlot Programming 13 10-17-2005 12:47 PM
Wine wont start program, segmentation fault, artsdsp nontoxic Linux - Software 3 03-21-2005 06:27 AM
Program received signal SIGSEGV, Segmentation fault ims_mca Linux - Distributions 0 03-09-2005 04:16 AM
libxml++: segmentation fault when exiting program. isl01jbe Programming 0 06-20-2004 05:47 AM
"segmentation fault" when run a simple c program acer_peri Programming 11 05-28-2004 04:14 AM


All times are GMT -5. The time now is 05:45 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration