Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!ut-sally!husc6!cmcl2!brl-adm!adm!franco@MIKEY.BBN.COM From: franco@MIKEY.BBN.COM (Frank A. Lonigro) Newsgroups: comp.unix.wizards Subject: scanf quiz winner!!!! Message-ID: <8530@brl-adm.ARPA> Date: Tue, 28-Jul-87 14:21:16 EDT Article-I.D.: brl-adm.8530 Posted: Tue Jul 28 14:21:16 1987 Date-Received: Thu, 30-Jul-87 00:49:35 EDT Sender: news@brl-adm.ARPA Lines: 31 Sorry!! But your winner is a loser!!! {|-)> The scanf line that was exclaimed to be a winner once again restricts the character strings to not have a certain char in them in this case a 'newline' (\n). This example follows: scanf("%s %[^#] %*c %[^\n]", s1, s2, s3); I have stated the correct way to handle the problem in a recent posting to unix-wizards. That example follows: scanf("%s %[^#] %*c %[\001-\177]", s1, s2, s3); ^^^^^^^^^ Please note that the format string doesn't restrict any chars from appearing in the final string except the NULL. Also, please note that an obvious change to the above example will not work: scanf("%s %[^#] %*c %[^\0]", s1, s2, s3); ^^^ This format string says the same thing as the previous(allow all chars BUT the NULL) but with one flaw. The format string is terminated by a NULL prematurely and the _doscan function will not see the closing ']' square bracket. Fortunately I discovered this problem when I moved our software from Ultrix 1.1 to 1.2, i.e.. The "%[^\0]" worked correctly under 1.1 but failed under 1.2 and all the scanf calls that used that format had to be changed to "%[\001-\177]", an easy task. {|-)> ^- Pat Sajak with punk sunglasses franco%bbn.com@relay.cs.net