C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 14th, 2003, 10:45 AM
Avenger Avenger is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 4 Avenger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question double pointer to a structure within a structure

i've been latly working on some project (neverminde the details), and i got stuck in this part....

there are two structures involved in this problem:

struct folder {
char name[20];
struct file **files;
struct folder *subfolder;
};

struct file {
char name[20];
char *info;
};

now the problem comes when i'm trying to do this:

int main () {

struct folder home =
{"home", (struct file *) calloc(2, sizeof(struct file)), NULL};

home.files[0] = {"test.txt" , NULL}; /* problem */
}

EOF

so the problem comes is the line i have marked with a comment. anyways, i'm trying to insert some values into one of the dynamicly allocated structures. but the compile says:

prase error before '{'

what have i done wrong? bah i guess i'll find my own mistake before i get an answer :\

BTW, this program runs under linux. gcc compiler.

Reply With Quote
  #2  
Old April 14th, 2003, 02:35 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,141 dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 23 h 52 m 21 sec
Reputation Power: 1974
First, I'm very leery of that declaration for struct folder home. I don't believe that you can call a function within an initialization list, but rather that the list's values must be known at compile time.

But the reason you're getting a parse error on the next line is because that's an assignment statement you're trying to use an initialization list in. Initialization lists belong in declarations.

Break your assignment statement up into a separate "assignment" (ie, including function calls like strcpy) for each field; eg:
Code:
strcpy(home.files[0].name,"test.txt");
home.files[0].info = NULL;

Last edited by dwise1_aol : April 14th, 2003 at 02:38 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > double pointer to a structure within a structure

Developer Shed Advertisers and Affiliates



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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap