First thing I spot it that this line is missing an asterisk:
char fname[CLASSSIZE][NAMELEN], *temp;
Then, you need to fix the loops appropriately (don't have time to test the correct solution here, you may get errors about l-values).
Your scanf function call is also missing on the lname and fname, so you don't fill your arrays properly.
Also, you ought not to need to declare "strncmp" before main. The inclusion of <string.h> means the function is already declared for you (unless you have been having specific issues).
As an aside, is it the case that you have to use parallel arrays for some reason? You would save yourself a good deal of effort if you package the lastname, firstname and age into a struct:
struct Person
{
char lname[NAMELEN];
char fname[NAMELEN];
int age;
};
This way, you store an array of pointers to the Person data type:
typedef struct Person PersonData;
PersonData* personList[CLASS_SIZE];
and then you can sort on the last name, swap the pointers in the array in just the way you are doing, but the firstname, surname and age are all tied together, also allowing you to add extra properties to the person (e.g. weight) and that would automatically get sorted with no extra sorting effort required.
Just a thought!
Hope this is helpful.
Enter your message below
Sign in or Join us (it's free).