Ok, I'm trying to sort an array of structures based on the last name member. I don't want to actually change it around physically so I want to use a pointer to it. My problem is how to "switch" up the values properly. BTW - I don't want to use the qsort() because I want to learn this. Here's the structure:
typedef struct psnger {
char LName[MAXLEN];
char FName[MAXLEN];
int SeatID;
int status;
} pseat;
pseat cust[MAXSEATS] (MAXSEATS = 12)
Here's the function I'm using.
void sort_alpha(pseat * cust, int bufsize)
{
int i, j;
pseat ** seat_s = &cust, **temp;
for (i = 0; (i < MAXSEATS && (*seat_s)->status != 0); i++)
{
for (j = i + 1; (j < MAXSEATS -1 && (*seat_s)->status != 0); j++, (*seat_s)++)
{
if (strcmp((*seat_s)->LName, ((*seat_s)+1)->LName) > 0)
{
temp = seat_s;
seat_s = seat_s + 1;
seat_s + 1 = temp;
}
}
}
}
Obviously, I'm getting an error because seat_s + 1 can't be an lvalue. I can't think of what else to do. I'm stumped. I've also tried to use malloc to do this sort which is why I'm passing the function bufsize, the size of the structure, but can't seem to get it quite right. Any help or suggestions would be great.
Thanks.
-Tyler
typedef struct psnger {
char LName[MAXLEN];
char FName[MAXLEN];
int SeatID;
int status;
} pseat;
pseat cust[MAXSEATS] (MAXSEATS = 12)
Here's the function I'm using.
void sort_alpha(pseat * cust, int bufsize)
{
int i, j;
pseat ** seat_s = &cust, **temp;
for (i = 0; (i < MAXSEATS && (*seat_s)->status != 0); i++)
{
for (j = i + 1; (j < MAXSEATS -1 && (*seat_s)->status != 0); j++, (*seat_s)++)
{
if (strcmp((*seat_s)->LName, ((*seat_s)+1)->LName) > 0)
{
temp = seat_s;
seat_s = seat_s + 1;
seat_s + 1 = temp;
}
}
}
}
Obviously, I'm getting an error because seat_s + 1 can't be an lvalue. I can't think of what else to do. I'm stumped. I've also tried to use malloc to do this sort which is why I'm passing the function bufsize, the size of the structure, but can't seem to get it quite right. Any help or suggestions would be great.
Thanks.
-Tyler