On Mon, Jun 23, 2008 at 01:43:39PM +0200, Michael Kerrisk wrote: [...] > > errno = 0; > > n = scanf(..., &p); > > if (n == 1) { > > printf("OK: %s\n", p); > > free(p); > > } else if (errno != 0) { > > perror("scanf"); > > } > > else { > > fprintf(stderr, "expected letters, not \"%s\"\n", ...);
Well, that error message would be OK for sscanf where you could use the scanned string for the %s above, but not for scanf, sorry. > > } > > Thanks for that piece of code. I'll include a version of that in the page. [...] One may also want to check for (n == EOF), though it's OK to treat n == 0 and n == EOF the same when you only need to check the correctness of the input (n==EOF means empty input). -- Stéphane -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]