Problems with write_to_output and buf (sprintf)

From: Mathew Earle Reuther (graymere@zipcon.net)
Date: 07/30/02


Here's a sample output from my list_valid_classes function:

Please Select a Profession:

 [Magical Studies] ->
 [Runic Languages] ->
 [Philosophy]      ->
 [Natural Theology]->
 [Natural Theology]-> (g)Animist
 [Natural Theology]-> (g)Animist  (h)Elementalist
 [Theology]        ->
 [War Theology]    ->
 [War Theology]    -> (m)Pathfinder
 [Warcraft]        ->
 [Warcraft]        -> (p)Hiresword
 [Warcraft]        -> (p)Hiresword  (q)Myrmidon
 [Subterfuge]      ->
 [Subterfuge]      -> (r)Corsair
 [Subterfuge]      -> (r)Corsair  (s)Guildsman
 [Musical Theory]  ->
 [Musical Theory]  -> (u)Meistersinger

It SHOULD Appear as such:

Please Select a Profession:

 [Magical Studies] ->
 [Runic Languages] ->
 [Philosophy]      ->
 [Natural Theology]-> (g)Animist  (h)Elementalist
 [Theology]        ->
 [War Theology]    -> (m)Pathfinder
 [Warcraft]        -> (p)Hiresword  (q)Myrmidon
 [Subterfuge]      -> (r)Corsair  (s)Guildsman
 [Musical Theory]  -> (u)Meistersinger

Or possibly:

Please Select a Profession:

 [Natural Theology]-> (g)Animist  (h)Elementalist
 [War Theology]    -> (m)Pathfinder
 [Warcraft]        -> (p)Hiresword  (q)Myrmidon
 [Subterfuge]      -> (r)Corsair  (s)Guildsman
 [Musical Theory]  -> (u)Meistersinger

As you can see, I'm getting the main category printed out once per class
the race can become plus one blank one.  I've tried placing the
write_to_output calls in various places, but have thusfar been
unsuccessful at making it show ALL classes a race can become within their
supercategory (which is mainly a descriptive that has help on a different
menu screen.)

The parsing of the class selections works fine, it will limit people as
they should be.  It is the display function that is hosed.  Here's some of
the actual code:

void list_valid_classes(struct descriptor_data *d) {
  char buf[MAX_STRING_LENGTH];

  sprintf(buf, "Please Select a Profession:\r\n\r\n [Magical Studies] ->
");
      write_to_output(d, buf);
    if (class_ok_by_race[(int)GET_RACE(d->character)][0]) {
      sprintf(buf + strlen(buf), "(%s)%s  ", classes[0].class_letter,
classes[0].class_name);
      write_to_output(d, buf); }
    if (class_ok_by_race[(int)GET_RACE(d->character)][14]) {
      sprintf(buf + strlen(buf), "(%s)%s  ", classes[14].class_letter,
classes[14].class_name);
      write_to_output(d, buf); }
    if (class_ok_by_race[(int)GET_RACE(d->character)][19]) {
      sprintf(buf + strlen(buf), "(%s)%s  ", classes[19].class_letter,
classes[19].class_name);
       write_to_output(d, buf); }

  sprintf(buf, "\r\n [Runic Languages] -> ");
      write_to_output(d, buf);
    if (class_ok_by_race[(int)GET_RACE(d->character)][16]) {
      sprintf(buf + strlen(buf), "(%s)%s  ", classes[16].class_letter,
classes[16].class_name);
      write_to_output(d, buf); }
    if (class_ok_by_race[(int)GET_RACE(d->character)][17]) {
      sprintf(buf + strlen(buf), "(%s)%s  ", classes[17].class_letter,
classes[17].class_name);
      write_to_output(d, buf); }

(and so on...)

As you can see, the reason it is printing out multiples is because I am
calling write_to_output a LOT.  However, if I *don't* call it that often
it will not display various classes based upon which others it does
display.  That was a sucky explanation, I know.  But essentially if it has
a write_to_output call in an if that becomes true, then the classes from
that subcategory are printed, if not, they are skipped.  But if I place
them in all like above, we see the problem.

Help?  What Am I doing wrong here?  Where SHOULD I place the calls?  The
format of the display is very important, btw, which is why I'm not just
using an incremented (grab a class number, check it, print it if they can
be it) method.  Thus I'm in need of help getting this particular format.
(I already know how to slap a quick list of classes together, but it's too
ugly and barbaric when you have some races which can be 15 classes.)

Thanks in advance for any assistance!

-Mathew

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT