Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!quick!srg
From: srg@quick.UUCP (Spencer Garrett)
Newsgroups: comp.bugs.misc
Subject: Re: doscan.o bug in Ultrix 1.2 & 2.0
Message-ID: <108@quick.UUCP>
Date: Sun, 12-Jul-87 20:26:07 EDT
Article-I.D.: quick.108
Posted: Sun Jul 12 20:26:07 1987
Date-Received: Mon, 13-Jul-87 05:42:09 EDT
References: <309@nsta.UUCP> <2852@ncoast.UUCP>
Organization: Quicksilver Engineering, Seattle
Lines: 20
Summary: proper way to skip optional whitespace

-> As quoted from <309@nsta.UUCP> by tom@nsta.UUCP (Tom Gorodecki):
-> +---------------
-> | Bug in doscan.o in /lib/libc.a on ULTRIX 1.2 and ULTRIX 2.0.
-> | Try in you program.c the following line:
-> | 
-> | val = fscanf(file,"%*[ \t\n]%74[abcdefghijklmnopqrstuvwxyz
-> | ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]", namebuf);
-> | 
-> | In case your input does not begin with space, tab or newline, scanf will 
-> | return 0 which is not right, since "*" should match "0 or more" .
-> +---------------

But the following code would work on any unix system I've ever encountered:

	val = fscanf(file, " %74[a-zA-Z0-9]", namebuf);

Whitespace in the format string matches OPTIONAL whitespace in the input
stream.  The %[] format requires that SOMETHING match its scanstring.
The * only means "0 or more" in regular expressions.  In the example
above it is being used to suppress storing the result of the match.