Perfect, thanks for the explanation! I have two more questions.
First, when I try to call the function, I get a warning:
warning: passing argument 1 of 'showgroup' from incompatible pointer type
Code:
struct person *pgroup[10];
showgroup(pgroup, 10);
I'm assuming I need to cast to const somehow but I'm not sure.
Question two:
I have a showsorted() function declared with the same arguments as before:
Code:
void showsorted(const struct person * const group[], int n)
{
int x;
int y;
struct person * copy[n];
struct person * tmp;
for (x = 0; x < n; x++)
copy[x] = &group[x]; // compiler shows warning here
for (x = 0; x < n - 1; x++) {
for (y = x + 1; y < n; y++) {
if (strcmp(copy[x]->lname, copy[y]->lname) > 0) {
tmp = copy[x];
copy[x] = copy[y];
copy[y] = tmp;
}
}
}
showgroup(copy, n);
}
I get the following warning:
warning: assignment from incompatible pointer type
So, I thought about it and came up with this (seems pretty messy):
Code:
void showsorted(const struct seat * const group[], int n)
{
int x;
int y;
const struct person * const * copy[n];
const struct person * const * tmp;
for (x = 0; x < n; x++)
copy[x] = &group[x];
for (x = 0; x < n - 1; x++) {
for (y = x + 1; y < n; y++) {
if (strcmp((*copy[x])->lname,
(*copy[y])->lname) > 0) {
tmp = copy[x];
copy[x] = copy[y];
copy[y] = tmp;
}
}
}
//showgroup(copy, n);
for (x = 0; x < n; x++) {
printf("fname: %s lname: %s\n",
(*copy[x])->fname, (*copy[x])->lname);
}
return;
}
Of course, I can't tell if it will work because I am stuck on actually calling the functions.