Problems with scanf()

Adrian McCarthy adrian at mti.mti.com
Tue Oct 30 08:40:07 AEST 1990


The VAX C 3.0 library version of sscanf() doesn't handle unsigned values at
all (according to the docs).  In particular I needed a text to unsigned long
conversion.  I used the strtoul() function, but I was wondering if anyone
knows if 3.1 added this functionality to sscanf().

Also, does Henry Spencer's commandment about checking the return values of all
functions for errors apply to sscanf()?  Since sscanf() is supposed to return
the number of successful conversions, it seems reasonable to do things like:

  if (sscanf(str, "%d %d", &x, &y) != 2) {
    fprintf(stderr, "Error parsing string.\n");
    exit(PARSE_ERROR);
  }

Right?

Aid.  (adrian at gonzo.mti.com)



More information about the Comp.lang.c mailing list