Thread: Structture problem

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    19

    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.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Without a clear idea of what the underlying structure is, it could be anything.

    Why the * here?
    printf(" TABLE &#37;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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jul 2007
    Posts
    19
    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 &#37;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..

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM