Thread: Help in structures and functions

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    1

    Help in structures and functions

    Hi,
    I have a struct in a .h file, and i want to use a function to define and initialize the struct and send a pointer back to main and use it.
    How should i do it?
    Does the struct needs global?
    Many thanks!

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    San Jose
    Posts
    2,633
    If you want a global instance of the struct, declare it with extern in the header....and without extern in the implementation file.
    Also.. declare your 'init' function in the .h file and define it in the .c file.
    That is a common way of doing things....if it suits you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help me with structures using functions
    By magnetpest2k7 in forum C Programming
    Replies: 2
    Last Post: 10-07-2009, 01:32 AM
  2. Functions in Structures
    By pritin in forum C++ Programming
    Replies: 1
    Last Post: 03-26-2007, 01:40 AM
  3. functions and structures
    By subflood in forum C Programming
    Replies: 2
    Last Post: 06-11-2005, 06:15 PM
  4. structures and functions
    By student2005 in forum C++ Programming
    Replies: 1
    Last Post: 10-16-2003, 04:12 PM
  5. structures and functions
    By akalvarado in forum C Programming
    Replies: 4
    Last Post: 11-24-2002, 10:09 AM