Thread: Pointer to Structure

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    8

    Angry Pointer to Structure

    If I have the following struct:

    struct tagPalette
    {
    unsigned int entry[256];
    };

    tagPalette Palette1;
    tagPalette *pPalette1; //Pointer to structure

    pPalette1 = &Palette1; //Point to Palette1

    How do I pass pPalette in a function, is it:

    Funct(pPalette1, pixel);

    Where the function is:
    Funct1(tagPalette PaletteNum, int Pixel)
    {
    a = PaletteNum->entry[pixel];
    }

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    You can pass the address of Palette1 when calling the function:
    Code:
    struct tagPalette 
    { 
    	unsigned int entry[256]; 
    }; 
    
    void Funct1(tagPalette *PaletteNum, int Pixel) 
    { 
    	printf("%d\n", PaletteNum->entry[Pixel]);
    	PaletteNum->entry[Pixel] = 20;
    }
    
    int main()
    {
    	tagPalette Palette1; 
    
    	Palette1.entry[0] = 10;
    	Funct1(&Palette1, 0);
    	printf("%d\n", Palette1.entry[0]);
    	return 0;
    }
    B.t.w.

    Avoid global vars if you can
    // is C++ comment, use /* ... */

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    Just a little correction. Using // for comments is also valid according to the latest C standard.

  4. #4
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Originally posted by Shiro
    Just a little correction. Using // for comments is also valid according to the latest C standard.
    But it's not supported by most C compilers....

  5. #5
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Shiro,

    Can you tell me where I can find the latest C standard?

    Many thanks,
    Monster

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Can you tell me where I can find the latest C standard?
    www.ansi.org

    -Prelude
    My best code is written with the delete key.

  7. #7
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Originally posted by Prelude
    >Can you tell me where I can find the latest C standard?
    www.ansi.org

    -Prelude
    I know that site but does the ANSI C standard has a number (like ANSI X9.19) that I can search on.

    B.t.w. Do you have to pay for this standard?

  8. #8
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    The number of the latest standard is C99 or ISO/IEC 9899:1999. Unfortunately the standard is not free.

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Actual proper copies do cost $$$

    But a free copy is here - it's the last public draft prior to the standard, so its going to be close enough for most people who are not writing compilers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. method returning a pointer to a structure
    By nacho4d in forum C++ Programming
    Replies: 3
    Last Post: 05-25-2009, 10:01 PM
  2. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  3. how to cast a char *mystring to a structure pointer ??
    By hanhao in forum C++ Programming
    Replies: 1
    Last Post: 03-29-2004, 08:59 AM
  4. Pointer to a structure
    By frenchfry164 in forum C Programming
    Replies: 5
    Last Post: 03-16-2002, 06:35 PM
  5. Pointer to structure problem
    By unregistered in forum C Programming
    Replies: 3
    Last Post: 12-24-2001, 07:54 AM