The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Segmentation fault big123456 Linux 0 07-20-2007 05:01 AM
Segmentation fault rshaikh AIX 2 04-16-2007 08:12 AM
segmentation fault rockgal High Level Programming 8 12-05-2006 12:16 PM
Segmentation Fault compbug UNIX for Dummies Questions & Answers 3 04-21-2006 10:43 AM
segmentation fault wojtyla High Level Programming 3 02-19-2005 02:53 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-21-2008
joey joey is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 15
segmentation fault

If I do this.
Assume

Code:
struct life
{
           char *nolife;
}

struct life **life;
// malloc initialization & everything

if(life->nolife[index] == 0)
Would I get error at life->nolife[index] if it is equal to 0.
wrong accession?
  #2 (permalink)  
Old 12-22-2008
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Quote:
Originally Posted by joey View Post
If I do this.
Assume

Code:
struct life
{
           char *nolife;
}

struct life **life;
// malloc initialization & everything

if(life->nolife[index] == 0)
Would I get error at life->nolife[index] if it is equal to 0.
wrong accession?
Perhaps they may be something more in the initialization code. What is index?
  #3 (permalink)  
Old 12-22-2008
spirtle spirtle is offline
Registered User
  
 

Join Date: Jun 2008
Location: Scotland
Posts: 150
Quote:
// malloc initialization & everything
The devil is often in the details, so please be explicit about how you are doing this.
Also, since life is a pointer to pointer to struct life,
Quote:
struct life **life;
then attempting to get a nolife member from it like this
Quote:
if(life->nolife[index] == 0)
is wrong and shouldn't compile.
  #4 (permalink)  
Old 12-22-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 750
spirtle is right nolife is a pointer to char while life is a pointer to pointer to struct so it shouldn't compile. And don't use same name for a structure tag and a dual level pointer.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0