Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!ccicpg!cracraft
From: cracraft@ccicpg.UUCP (Stuart Cracraft)
Newsgroups: comp.unix.wizards
Subject: Re: scanf quiz question
Message-ID: <1262@ccicpg.UUCP>
Date: Fri, 24-Jul-87 13:02:44 EDT
Article-I.D.: ccicpg.1262
Posted: Fri Jul 24 13:02:44 1987
Date-Received: Sat, 25-Jul-87 15:49:00 EDT
References: <1220@ccicpg.UUCP>
Reply-To: cracraft@ccicpg.UUCP (Stuart Cracraft)
Organization: CCI CPG, Irvine CA
Lines: 38

There were a number of replies to this quiz question. Only one
person answered the question correctly. First, let me restate
the quiz question:

   >Suppose you have an input line of the form:
   >
       >str1      str2 str3 str4 ... strN    # strN+1 ... strN+I
   > ^                 ^                          ^
   > |                 |                          |
   > Store in s1       |                          |
   >		   Store in s2                Store in s3
   >
       >The above line consists of three fields:
   >      1) str1
   >   2) str2 ... strN (where N is up to 10)
   >   3) strN+1 ... strN+I (where I is up to 10)
   >(strX represents an arbitrary-length string, up to 20 characters.)
   >How do you parse this line using scanf?

Many people correctly answered for the first argument. It is simply
%s in the scanf scan string. Some people, though fewer, correctly
answered for the second argument. It is simply [^#] in the scan
string. This takes advantage of the scanf ^ 'complement' operator
to create a 'breakset'. When it came to the third argument however,
just about everyone missed, except for our winner.

Our winner correctly pointed out that a non-assignment argument must
also be supplied, and he correctly deduced the breakset for the
final argument as well. Here is the correct answer:

    scanf("%s %[^#] %*c %[^\n]",s1,s2,s3);

Congratulations to our winner, Leonard Binns!

	Stuart

P.S. Other answers may exist. The quiz manufacturer disclaims
     any responsibility for additional solutions.