Thread: How to call a function several times, but with a different structure as argument?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    26

    How to call a function several times, but with a different structure as argument?

    Hi

    I have written a function where I can save a structure in a file. So the prototype looks like this:
    Code:
    void SaveStructure(FILE *f, STRUCTURE *structure);
    The structure looks for example like this:
    Code:
    typedef struct
    	{
    		int dummy;
    		char text[30];
    
    	} STRUCTURE ;
    Now I want to use the function SaveStructure(...) again, but with this structure for example:
    Code:
    typedef struct
    	{
    		int nr;
    		char name[30];
    		char street[30];
    
    	} NEW_STRUCTURE ;
    How can I make it possible that the function SaveStructure(...) doesn't care how the structure looks like?
    Does the format of the pointer struct always looks the same? So could I make a dummy-structure:
    Code:
    typedef struct
    	{
    		int dummy
    
    	} SAVESTRUCT;
    and use the function:
    Code:
    void SaveStructure(FILE *f, SAVESTRUCT *structure);
    this way?
    Code:
    void main (void)
    {
    	FILE *f1 = NULL;
            FILE *f2 = NULL;
    	STRUCTURE structure;
    	NEW_STRUCTURE new_structure;
    
    	SaveStructure(f1, &structure);
    	SaveStructure(f2, &new_structure);
    
    	return;
    }
    thx for any help....
    Last edited by mabuhay; 02-13-2006 at 11:02 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C interview questions
    By natrajdreams in forum C Programming
    Replies: 7
    Last Post: 12-12-2010, 12:40 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. how to get function call stack
    By George2 in forum C Programming
    Replies: 18
    Last Post: 11-11-2006, 07:51 AM
  4. passing counters between function
    By BungleSpice in forum C Programming
    Replies: 18
    Last Post: 02-21-2004, 06:16 PM
  5. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM