LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 09-26-2001, 11:23 PM   #1
wsimmons
LQ Newbie
 
Registered: Sep 2001
Posts: 10

Rep: Reputation: 0
Question segmentation fault w/ c++ function call


I am getting a segmentation fault (core dumped) when a program that I am writing calls the following function:

void test_fx()
{
MainDataSetPtr here_ptr;//local scope
here_ptr = head;
do
{
cout<<head->d_structCloneID<<"\n";
cout<<head->d_structSubclone<<"\n";
//a few more struct variables that I don't want to
//take the time to write at the moment
here_ptr = here_ptr-> link_down;
}while (here_ptr-> link_down != NULL);
return;
}

The struct worked fine in other functions (I can load it with data)that I have used in the porgram. but now that I am trying to extact the data from it for processing (including file output streams) there seems to be difficulty in the programming. Any help with this? Thank you.
 
Old 09-27-2001, 01:18 AM   #2
isajera
Senior Member
 
Registered: Jun 2001
Location: San Antonio, TX
Distribution: distro? what's a distro?
Posts: 1,635

Rep: Reputation: 45
where exactly is the program seg faulting? is it printing anything out at all, or does it just dump immediately?
 
Old 09-28-2001, 05:59 PM   #3
pinoy
LQ Newbie
 
Registered: Sep 2001
Posts: 21

Rep: Reputation: 15
This is the same post I replied to at Linuxnewbie.org. I'll give you the answer this time though.

Code:
    here_ptr = here_ptr-> link_down; 
}while (here_ptr-> link_down != NULL);
Never dereference a NULL pointer.

Code:
    here_ptr = here_ptr-> link_down; 
    if (here_ptr == NULL)
        break;
}while (here_ptr-> link_down != NULL);
 
Old 10-16-2001, 02:06 AM   #4
karakonchar
LQ Newbie
 
Registered: Oct 2001
Posts: 1

Rep: Reputation: 0
Lots of problems in the code. I assume that you intend to traverse and print a linked list. But the code always prints head node.

Seg. fault will occure if head is NULL. Or it might be occuring in the while condition. Change the while condition to following.

while (here_ptr) ;

With the condition you are using you will not be able to print the last node.
 
  


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
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika Suse/Novell 2 12-02-2005 09:34 AM
segmentation fault samprabhu Linux - General 3 07-29-2005 07:17 PM
How to call another function from a function? geminigal Programming 4 04-21-2005 10:41 PM
No Matching Function for Call ! vipinsharma Programming 2 07-05-2004 01:58 PM
how to call function?? harpal Programming 3 04-29-2003 05:59 AM


All times are GMT -5. The time now is 09:06 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