Re: [Code] simple_mob, adding new value

From: Admin of The Keep (dkoepke@california.com)
Date: 10/13/96


On Sun, 13 Oct 1996, annick elziere wrote:

> Or, in db.c what could i do, if there is nothing there, to
> just set to 0?  I am not familliar with writeing to files
> yet and would love any help i can get.

  Oh, blah... :)  Didn't I just explain how to do this early this month?!
  Anyway, the code is using sscanf() to search through the string for each
  value.  sscanf() returns the number of matched values it got...

  So:

    string = "1d50 hello 3";
    printf("%d", sscanf(string, "%dd%d %s %d", &a, &b, c, &d);

  Would return 4.  If you have only 3 arguments, it'd return 3.  In this
  way you can make arguments optional.  If it's not there, don't report
  any problems and just set it to 0.  For instance:

    string = "1d50 hello 3";
    if ((x = sscanf(string, "%dd%d %s %d", &a, &b, c, &d)) < 3)
      fprintf(stderr, "Got less than three arguments.\n");
    if (x < 4)
      d = 0;
  
  If you'll notice, we're checking if it has less than THREE arguments,
  even though we are looking for four.  This means that it won't report
  any problems if it encounters only three items on the line.  We also
  set 'd' to zero (a default value) when we find out that we didn't get
  our fourth argument.

  Oh, a quick note.  The '%dd%d' searches for INTEGER 'd' INTEGER, with
  the 'd' being there as context ('%d %d' would get two integers that
  are seperated by a space, '%dd%d' gets two seperated by 'd').

  IMHO, not upwardly difficult to devise by exmaining the code.


  <*=-+Daniel+-=*>
  "Forgive me father, for I am sin."


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



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