Pardon the seemingly excessive usage of code in advance:

Twice now I've gotten to a point in C where I feel comfortable only to come back and have the rug taken out from under me - as if I misunderstood the lesson and went along my way doing it wrong all the way.
I just yesterday finished a exercise in my book C primer plus 4th edition that asked me to sort an array of struct alphabetically. I used the selection sort algorithm as in the following code
Code:
void Show(struct CAF arg[]){
     int ndx,ndx2;
     struct CAF *temp;
     struct CAF *ptr_arg[SEAT_NUM];
     
 /*assign ptr_struct the proper addy */
      for(ndx=0;ndx<SEAT_NUM;ndx++)
     ptr_arg[ndx] = &arg[ndx];

/*sort the structures; if struct nxt comes before struct prev then swap them */
    for(ndx=0;ndx<SEAT_NUM;ndx++){
      for(ndx2=ndx+1;ndx2<SEAT_NUM;ndx2++){
      if( (strcmp(ptr_arg[ndx2]->LastName,ptr_arg[ndx]->LastName) ) < 0){//comes before 
        temp = ptr_arg[ndx2];
        ptr_arg[ndx2] = ptr_arg[ndx];
        ptr_arg[ndx] = temp;
        }
    }
}
     
/*show the sorted list but only sort the ones that are TAKEN SHOULD APPLY 
this to the sort logic above as well. only sort the ones that are taken. less
time and more efficient*/
for(ndx=0;ndx<SEAT_NUM;ndx++)
      if ( (ptr_arg[ndx]->SeatStatus==TAKEN) )
          printf("seat %d: %s, %s\n", ptr_arg[ndx]->SeatNum,ptr_arg[ndx]->LastName,
          ptr_arg[ndx]->FirstName);
}
assuimg a struct of
Code:
struct CAF{
       int SeatNum;
       int SeatStatus;
       char LastName[MAX];
       char FirstName[MAX];
       };
       
struct CAF Seats[SEAT_NUM];
now originally my code was as follows
Code:
/*show the sorted list */
for(ndx=0;ndx<SEAT_NUM;ndx++)
      if ( (arg[ndx]).SeatStatus )
          printf("seat %d: %d %s %s\n", arg[ndx].SeatNum,arg[ndx].SeatStatus,arg[ndx].FirstName,
          arg[ndx].LastName);
and I was shown the error of my ways. My question is why? As far as i understood and working under that assumption: a pointer stores the address of a var. dereference that pointer you canget to that addy of the object and change its value via the pointer.
ptrs enable you to change objects values in different scopes. so why
when sorted do i need to put addy of the ptr_arg and not the arg itself
my understanding up to this point where they were one and the same and
you put const if you didn't want to change the value the ptr pointed to?

examples which served to reinforce my belief were such things as a simple swap code
Code:
#include <stdio.h>
void interchange(int * , int * );
int main(void)
{
    int x = 5, y = 10;
    

    printf("Originally x = %d and y = %d.\n", x, y);
    interchange(&x, &y);  /* send addresses to function  */
    printf("Now x = %d and y = %d.\n", x, y);
    getchar();
    return 0;
}

void interchange(int * x, int * y)
{
    int temp;/*temp just needs to hold an integer, not a pointer */

    temp = *x;       /* temp gets value that u points to */
    *x= *y;
    *y= temp;/*which was x */
}
the original values are obviously change by using pointers to get to their addy's.
To confound me even more
Code:
/* names1.c -- passes structures by reference to funcions.*/
#include <stdio.h>
#include <string.h>

struct namect {
    char fname[20];
    char lname[20];
    int letters;
};
void getinfo(struct namect *);
void makeinfo(struct namect *);
void showinfo(const struct namect *);
int main(void)
{
    struct namect person;

    getinfo(&person);
    makeinfo(&person);
    //showinfo(&person); /*uses *person to change info */
    
/*this was changed using a pointer to person so it changed the struct */
    puts(person.fname);
    puts(person.lname);
    printf("you have %d lets in your name",person.letters);
   
    getchar();
    return 0;
}

void getinfo (struct namect * pst)
{
    printf("Please enter your first name.\n");
    gets(pst->fname);
    printf("Please enter your last name.\n");
    gets(pst->lname);
}

void makeinfo (struct namect * pst)
{
    pst->letters = strlen(pst->fname) +
                   strlen(pst->lname);
}

void showinfo (const struct namect * pst)
{
    printf("%s %s, your name contains %d letters.\n",
        pst->fname, pst->lname, pst->letters);
}
As you can see Show info changed the info at person.firstname and letters and instead of using pst->fname to print that change i used the original value because it is changed right?
Then last piece of code is this
Code:
/* sort_str.c -- reads in strings and sorts them */
#include <stdio.h>
#include <string.h>
#define SIZE 81        /* string length limit, including \0  */
/* is this really necessary though */
#define LIM 20         /* maximum number of lines to be read */
#define HALT ""        /* null string to stop input          */
void stsrt(char *strings[], int num);/* string-sort function */
int main(void)
{
  char input[LIM][SIZE];       /* array to store input       */
  char *ptstr[LIM];            /* array of pointer variables */
  int ct = 0;                  /* input count                */
  int k;                       /* output count               */

  printf("Input up to %d lines, and I will sort them.\n",LIM);
  printf("To stop, press the Enter key at a line's start.\n");
  while (ct < LIM && gets(input[ct]) != NULL && input[ct][0] != '\0')
  /* this terminates input as it points to null this is the first letter of the word being 
  entered, as long as its not '\0' then its a word. I see*/
  
                              
  {
     ptstr[ct] = input[ct];    /* set ptrs to strings. this copies the words to ptstr      */
     ct++;//increment word count
  }
  stsrt(ptstr, ct);            /* string sorter, and the number of words to sort */
  puts("\nHere's the sorted list:\n");
  for (k = 0; k < ct; k++)

     puts(ptstr[k]) ;           
  getchar();
  return 0;
}
/* string-pointer-sorting function using selection sort algorithm. this sorts
pointers to char not the actual words themselves?? */
void stsrt(char *strings[], int num)
/* this sorts an array of pointers. so its sorting the first letter of each pointer and it
moves up*/
{
  char *temp;
  int top, seek;

  for (top = 0; top < num-1; top++)/* num - 1 is the element -1 for the null character */
     for (seek = top + 1; seek < num; seek++)
        if (strcmp(strings[top],strings[seek]) > 0)//if top comes before seek
        
        {
            temp = strings[top];
            strings[top] = strings[seek];
            strings[seek] = temp;
        }
}
this code read back what you sorted. but if I replace ptsr with input value would remain unchange.
obvioulsy its only sorting ptsr but why, ptsr is a *input so any changes to ptsr unless it is
qualified as constant should result in changes to input as well.
you use ptrs_totype to avoid making auto copies of objects and wasting memory. I understand that
but how is that input remains unchanged, what am i missing???
I'm utterly confused by this. Someone please put in a light I can understand cause I can't imagine what piece of info i'm missing to click it into place. Its annoying!!!