Thread: Passing an array of structs

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    1

    Question Passing an array of structs

    Hi I'm new to this forum. Sorry if how I present my problem is not the correct way.

    What I'm trying to do is pass an array of structures to a function. Here is glimpse of the relevant parts of my code.

    Code:
    ...
    void manual_replace ( struct key *key_list, char *txt_p, int size); <-- prototype
    ...
    
    int main (void) 
    {
           ...
           struct key{
    	    char encoded;
    	    char decoded;
            };
    	
            struct key key_list[26];
           ...
           manual_replace(key_list, text, text_size); <-- calling the function
           ...
           return 0;
    }
    
    void manual_replace ( struct key *key_list, char *txt_p, int size)
    
    {
    	printf("%c", key_list[1].encoded);
    	printf ("%c %d", txt_p[0], size);
    	getchar();
    
    	return;
    }
    The other arguments work just fine. It's only when I call a part of a struct that I get an error. BTW I can't do anything that is C99 only (class rules ).

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    What error?

  3. #3
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    What error are you getting?

    If it's telling you that struct key is undefined you need to move

    Code:
    struct key{
      char encoded;
      char decoded;
    };
    outside of main
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help passing nxn array to 2d array.
    By beglaryanh in forum C Programming
    Replies: 2
    Last Post: 06-06-2009, 05:23 PM
  2. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  3. Creating array of structs
    By knirirr in forum C++ Programming
    Replies: 12
    Last Post: 06-18-2008, 08:30 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM

Tags for this Thread