C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-03-2009, 10:43 PM   #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 ).
SleepingUdon08 is offline   Reply With Quote
Old 04-03-2009, 11:13 PM   #2
cas
Registered User
 
Join Date: Sep 2007
Posts: 448
What error?
cas is offline   Reply With Quote
Old 04-03-2009, 11:23 PM   #3
Banned
 
ಠ_ಠ's Avatar
 
Join Date: Mar 2009
Posts: 533
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
__________________
╔╗╔══╦╗
║║║╔╗║║
║╚╣╚╝║╚╗
╚═╩══╩═╝
ಠ_ಠ is offline   Reply With Quote
Reply

Tags
array, functions, structs

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help passing nxn array to 2d array. beglaryanh C Programming 2 06-06-2009 05:23 PM
Dynamic array of structures containing yet another dynamic array of structures innqubus C Programming 2 07-11-2008 07:39 AM
Creating array of structs knirirr C++ Programming 12 06-18-2008 08:30 AM
Quick question about SIGSEGV Cikotic C Programming 30 07-01-2004 07:48 PM
Passing pointers between functions heygirls_uk C Programming 5 01-09-2004 06:58 PM


All times are GMT -6. The time now is 05:22 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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