|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
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. |
|
#2
|
||||
|
||||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > double pointer to a structure within a structure |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|