[comp.lang.c] Scanf question

ebm@corvair.almaden.ibm.com (Eli Messinger) (10/10/90)

I'm trying to scan a formatted line that looks like:

	ccssss(tab)number(tab)number(tab)number\n

Where c are single characters, and s is a >=0 character string.

Originally I tried using the format string:

	"%c%c%s%n%n%n"

which failed, as the %s string must be blank or \n terminated.  Next
I tried:

	"%c%c%[^\t]%n%n%n"

which failed when the string was null, since the [^\t] must apparently
match at least one character for the scanf to continue.

My only solution so far is to split the scan in two, scanning the first
three and last three parameters separately (searching for the tab in
between).  Anyone have a better suggestion?  Email please.
--
		    "Hang on to your ego."  --Brian Wilson
	
      CSNET: ebm@ibm.com / UUCP: ..!uunet!ibmarc!ebm / BITNET: ebm@almaden

peter@ficc.ferranti.com (Peter da Silva) (10/10/90)

Doctor! It hurts when I do this!

Don't use scanf if you have the slightest doubt about its ability
to solve the problem. For this one I'd use regexp or equivalents
if I wanted to be lazy, or strchr() in a loop if I wanted to do it
right.
-- 
Peter da Silva.   `-_-'
+1 713 274 5180.   'U`
peter@ferranti.com