Help in structures and functions

This is a discussion on Help in structures and functions within the C Programming forums, part of the General Programming Boards category; Hi, I have a struct in a .h file, and i want to use a function to define and initialize ...

  1. #1
    Ebb
    Ebb is offline
    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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,526
    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.
    Manasij Mukherjee | gcc-4.9.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



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, 02:32 AM
  2. Functions in Structures
    By pritin in forum C++ Programming
    Replies: 1
    Last Post: 03-26-2007, 02:40 AM
  3. functions and structures
    By subflood in forum C Programming
    Replies: 2
    Last Post: 06-11-2005, 07:15 PM
  4. structures and functions
    By student2005 in forum C++ Programming
    Replies: 1
    Last Post: 10-16-2003, 05:12 PM
  5. structures and functions
    By akalvarado in forum C Programming
    Replies: 4
    Last Post: 11-24-2002, 11:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21