First, here's a quick background: I've been assigned to modify this 'circleMUD' for my grade 12 summative, and my teacher has asked us to do several things that he hasn't taught us. As well as him wandering off and not staying focused when I tried to get help from him on this problem, we have never been officially taught pointers, and the indirect referencing in this code was the first time I've ever tried to do such a thing. One of the tasks is to add sorting functionality to a command that displays all the characters names currently online, and as you'll notice, I've put no attention into efficiency.

Anyways, the program compiles (and, amazingly enough, it sorts [I think] ), but I've clearly messed something up - as when I test the 'who' command (which is the code shown below, which I am trying to modify) by opening and connecting multiple users, the command appears in the next person's screen, as well as any following commands. It's sort of as if the person who uses the 'who' command hijacks the next player's game, and takes over their user. (however, output is still displayed on the original person's console, and that person, too, can hijack another person's game, as long as it's not the person who's controlling theirs)

I wasn't sure if this needed any more explanation, however I've added comments saying what I've intended on a line doing - and hopefully that will be enough.
Code:
              
ACMD(do_who)
{
  struct descriptor_data *d;
  struct char_data *tch, *ntch;
  struct descriptor_data swap;
  struct descriptor_data *next;

     .... Other unimportant declairations and code, for about 50 lines ...

for(;;success = 0) {                                  // if sort is completed without changes
    for (d = descriptor_list; d && d->next; d = d->next) {
      if (d->original)                                       // if d->original has content, use that
        tch = d->original;                      // tch isn't an acronym, and has no real meaning
      else if (!(tch = d->character))                                   // or else, use d->character
        continue;                                     // or else quit, because something is wrong
    
	  if (d->next->original)                                        // this is for the next descriptor
	    ntch = d->next->original;             // if the next ->original has content, use that
	  else if (!(ntch = d->next->character))           // or else use next ->character
		continue;                                 // or else quit, because something is wrong


	  if (GET_LEVEL(tch) < GET_LEVEL(ntch)) {         //this level to next descriptors level
	    next = d->next->next;    // marks the point of the 3rd descriptor after the current 1
	    swap = *d;                             // swap takes everything from current descriptor
	    *d = *d->next;                        //  everything in next descriptor copies into current
	    d->next = swap.next;       // fixes the broken link in list, pointing current to next
	    *d->next = swap;         //  everything in the next becomes what used to be in first
	    d->next->next = next;     //the 'next' pointer in second link is fixed, points to 3rd		
	    success++;                     // marks that a change has been made, to continue sort
	  }
	}
	if(!success)         
		break;
  }

                  .... and continues on for about 50 lines ...
Thanks for taking the time to read this lengthy post, and I'd greatly appreciate any response.