-
Structture problem
I have a problem with this function. My program crashes when I try make my structure "f_table[x].table.u_value" point to my array of pointers.... Is this the correct way of making the assignement?
At the beginnig of the function I make my structure point to the first element of my array of pointers "f_table[0].table.u_id=a_p_ibuf[0];".
Code:
nt fill_inc_struct(char *a_p_ibuf[], FTABLE *f_table, int total)
{
int i=0, x=0;
f_table[0].table.u_id=a_p_ibuf[0];
for (i=0; i<total; i++)
{
printf(" Before assignment %s\n",a_p_ibuf[i] );
f_table[x].table.u_value=(int*)(a_p_ibuf+i);
x++;
i++;
printf(" TABLE %s \n", *(f_table[x].table.u_id));
}
return 1;
}
Many thanks.
-
Without a clear idea of what the underlying structure is, it could be anything.
Why the * here?
printf(" TABLE %s \n", *(f_table[x].table.u_id));
If you're using gcc, then
gcc -W -Wall -ansi -pedantic prog.c
will tell you a lot about your code.
-
The structure is like this
Code:
typedef struct incl_table{
char *t_flag;
union final_table{
char *u_id;
int *u_value;
}table;
}FTABLE;
Here "printf(" TABLE %s \n", *(f_table[x].table.u_id));" I am trying to print the value the pointer is pointing to. But my problem is not there it is when i try to make my structure point to my array of pointers: "f_table[x].table.u_value=(int*)(a_p_ibuf+i);"
Thanks..
-
To be honest, I don't really understand the reason for having an "int *" and "char *" in a union - it makes very little sense to unionize two pointers that way - unless you are trying to avoid a cast, but if that's the goal, I think a cast is actually MORE readable.
--
Mats