scanf() question answered

Eli Messinger ebm at corvair.almaden.ibm.com
Thu Oct 11 06:01:01 AEST 1990


To recap:  I'm trying to scan a line of the form ccssss(tab)d, where c are
single characters, s is a >=0 length string, and d is an integer.

The problem is that there seems to be no simple way to make scanf() scan for
a >=0 length string.  If you use %s, then scanf skips blank space, and in the
case where the string is empty, gets the wrong answer.  If you use %[^t] then
an empty string matches 0 characters, which causes the scanf() to halt.

The consensus is: Don't use scanf.  (One solution that was proposed by a few
different people is to scan the line as: %[^\t]%d, then pick the first two
characters off).

	
--
		    "Hang on to your ego."  --Brian Wilson
	
      CSNET: ebm at ibm.com / UUCP: ..!uunet!ibmarc!ebm / BITNET: ebm at almaden



More information about the Comp.lang.c mailing list