Re: fscanf prob

From: Peter Ajamian (
Date: 01/04/00

Michael Gallagher wrote:
> i've been trying to make the shop's bank account save to a seperate file.
> (i know there's probably an easier way to do it but this suits me fine)
> and this is the code that reads it:
>      if (!(bank = fopen(fbank, "r"))) {
>        return;
>      }
>      fscanf(bank, " %d ", temp);
>      SHOP_BANK(shop_nr) = temp;
>      fclose(bank);
> and it saves fine, just when it reads at bootup the mud freezes.
> I can't figure out whats wrong.

fscanf is (imho) a bit picky in that it wants to see EXACTLY what you
specify.  For a bit more flexibility try using fgets in combination with
atoi as follows...

fgets(buf, MAX_STRING_LENGTH, bank);
SHOP_BANK(shop_nr) = atoi(buf);

The nice thing about this is atoi will skip any leading whitespace and
doesn't care about trailing whitespace (including the /n that ends up
being the last char on the line), this makes it very forgiving in terms
of exact formatting of the input.

Regards, Peter

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  |

This archive was generated by hypermail 2b30 : 04/10/01 PDT