/* --------------------------------------------------------- Sample definitions of passing an array of structures in C Fritz Ruehr / Willamette Computer Science / Spring 1999 --------------------------------------------------------- */ /* --------------------- This is a simple structure to represent people --------------------- */ struct person { char* first; char* last; int age; }; /* --------------------- This is a sample function which gets an array of structures passed to it as an argument by main. Note that we need to declare the function first, before we use it (or give a prototype). --------------------- */ void process(struct person temp[]) { printf("First person's first name was: %s\n", temp[0].first); } /* --------------------- The main just creates a little structure of people and then calls the process function, passing the array as its only argument. In reality, C just passes a pointer to the first structure, since an array is (roughly) just a pointer. --------------------- */ void main() { struct person testpeople[] = { { "Fred", "Jones", 25 }, { "Sam", "Smith", 21 }, { "Suzy", "Jones", 23 } }; process(testpeople); printf("... and all done.\n"); } /* --------------------------------------------------------- End of structure-passing sample --------------------------------------------------------- */