Re: [CODE] Crashing

From: peter hartman (wart@KUNTRYNET.COM)
Date: 03/31/98


Thanks for the help.  I checked my buffer, and it was using something
strange and odd so I added one in.  The player file was overriding the
buffer (I think).  Here is the finished code for a do_players command that
allows you to search for specific player levels and it'll list 'em
(without crashing).


ACMD(do_players)
{
  FILE *fl;
  struct char_file_u player;
  int done=FALSE;
  char buf[MAX_STRING_LENGTH];
  char arg1[MAX_INPUT_LENGTH], arg2[MAX_INPUT_LENGTH];
  int lowl, highl;

  two_arguments(argument, arg1, arg2);
  if (!*arg1 || !*arg2)
  { send_to_char("Must provide low and high levels.\r\n", ch);
    return;
  }
  else
  {
    lowl = atoi(arg1);
    highl = atoi(arg2);
  }
  if (!(fl = fopen(PLAYER_FILE, "r+")))
  { send_to_char("Can't open player file.  Uh oh.", ch);
    return;
  }
  sprintf(buf, "Player Name             Player Level\r\n");
  while (!done)
  { fread(&player, sizeof(struct char_file_u), 1, fl);
    if (feof(fl))
    { fclose(fl);
      done = TRUE;
    }
    if (!done)
      if (player.level >= lowl && player.level <= highl)
        sprintf(buf, "%s%-20s %-2i\r\n", buf, player.name, player.level);
  }
  send_to_char(buf, ch);

}


Wart || mud.kuntrynet.com:4000 || http://mud.kuntrynet.com/~wart/mud

"You did all the talking and me"
 -- Laurie Anderson


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST