Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!aplcomm!uunet!world!unixland!bill From: bill@unixland.uucp (Bill Heiser) Newsgroups: comp.lang.c Subject: sorting an array of structures Message-ID: <1990Nov18.220758.3490@unixland.uucp> Date: 18 Nov 90 22:07:58 GMT Organization: The Think_Tank BBS & Public Access Unix Lines: 38 I'm writing a program for a C class, and am looking for tips on how to sort an array of structures. I understand how to sort a normal array, but I'm unsure of this one... (it's due in a couple of days, but I'm working hard to finish it :-) The structure looks like this: #define NUMFLIGHTS 100 #define NUMPASSENGERS 500 struct p_rec { char name[50]; int seats; }; struct flight { int flight_num; int seats_left; struct p_rec passenger[NUMPASSENGERS]; } flight[NUMFLIGHTS]; I need to print a list of available seats, sorted in order by flight number. I guess somehow I need to sort the structure based on the contents of flight_num. In a different part of the program, I need to sort the passenger list for a specific flight. I guess in that case I need to get to the right flight number, then sort the p_rec structure on name. Any hints/clues/suggestions would be appreciated, especially if they're before Monday night :-) (it is due on Tuesday). bill -- home: ...!{uunet,bloom-beacon,esegue}!world!unixland!bill bill@unixland.uucp, bill%unixland.uucp@world.std.com Public Access Unix - Esix SYSVR3 - (508) 655-3848 other: heiser@world.std.com Public Access Unix (617) 739-9753