Thread: need help with structures

  1. #1
    rozner9124
    Guest

    need help with structures

    Hi,

    I am having some trouble creating a data type to be used in more than one file. I would just like some clarification on this.

    I know this works:
    Code:
    typedef struct {
    	char ID[10];
    	char *name;
    	unsigned int num;
    	char *address;
    	char phoneNumber[10];
    } Customer;
    
    Customer new_cust[10]; // create array of 10 customers
    The problems arise when I want to use this another file which we'll call funcs.c and of course funcs.h. I'm going to be passing a Customer from the main program to one of the functions declared in funcs.c, now the problem is: where do I declare this typedef. I originally tried in both the c files and ran into some compile warnings in the h file. When declaring this in the h file, that gave some more warnings. If anyone can help me out, it would be much appreciated. Thanks.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Make a header for it.
    Code:
    #ifndef SOMETHING
    #define SOMETHING
    typedef struct {
    	char ID[10];
    	char *name;
    	unsigned int num;
    	char *address;
    	char phoneNumber[10];
    } Customer;
    #endif
    Then just include the header wherever you need to use it.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Structures, passing array of structures to function
    By saahmed in forum C Programming
    Replies: 10
    Last Post: 04-05-2006, 11:06 PM
  3. Input output with structures
    By barim in forum C Programming
    Replies: 10
    Last Post: 04-27-2004, 08:00 PM
  4. pointers to arrays of structures
    By terryrmcgowan in forum C Programming
    Replies: 1
    Last Post: 06-25-2003, 09:04 AM
  5. Methods for Sorting Structures by Element...
    By Sebastiani in forum C Programming
    Replies: 9
    Last Post: 09-14-2001, 12:59 PM