array of pointers to struct in c : how?
So I'm writing a program in straight c (gcc compiler in slackware 11).
Code:
struct vox_node { Code:
struct vox_node *p_table[4]; Code:
p_table = calloc(sizeof(struct vox_node), 4); Code:
p_table[1] = (struct phoneme_node *) NULL; Code:
p_table = (struct vox_node *) calloc(sizeof(struct vox_node), 4); Code:
warning: assignment from incompatible pointer type Code:
error: incompatible types in assignment I've had this sort of problem before and in the past I've fixed it by doing very evil things with void and char and in generally being very architecture-dependent and nonportable. This time I'd like to use the "proper" way. Thank you in advance. |
Code:
struct vox_node *p_table[4]; Code:
p_table = calloc(sizeof(struct vox_node), 4); Code:
p_table = (struct vox_node *) calloc(sizeof(struct vox_node), 4); Code:
p_table[1] = (struct vox_node *) calloc(sizeof(struct vox_node), 1); |
The hardest thing about doing fancy structures in "C" is visualizing what you are trying to do. Sit down with a legal-pad and a number-two pencil and draw it out.
|
Quote:
|
> An old lesson I keep forgetting: when in doubt, delete the whole mess and start over.
thats a lesson? i guess it works while you are at the stage where you do things wrong the first time. however it seems like it might be a little counter productive once you start doing things right. might be worthwhile to come up with a new lesson. :) |
I agree with moob8, there are so many times I've been strung out on a piece of code not working, and the best way (IMO) is to delete and start fresh.
|
hi everyone. It's my first post here :)
1. Quote:
2. Quote:
3. Quote:
Hope this is not misleading.If wrong please correct me |
All times are GMT -5. The time now is 01:05 PM. |