Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!husc6!cmcl2!rutgers!lll-lcc!lll-tis!ptsfa!ihnp4!cbosgd!cwruecmp!hal!ncoast!allbery From: allbery@ncoast.UUCP (Brandon Allbery) Newsgroups: comp.unix.wizards Subject: Re: scanf quiz winner!!!! Message-ID: <3731@ncoast.UUCP> Date: Sun, 2-Aug-87 11:43:43 EDT Article-I.D.: ncoast.3731 Posted: Sun Aug 2 11:43:43 1987 Date-Received: Tue, 4-Aug-87 01:31:47 EDT References: <8530@brl-adm.ARPA> Reply-To: allbery@ncoast.UUCP (Brandon Allbery) Followup-To: comp.unix.wizards Organization: Cleveland Public Access UN*X, Cleveland, Oh Lines: 22 As quoted from <8530@brl-adm.ARPA> by franco@MIKEY.BBN.COM (Frank A. Lonigro): +--------------- | 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); +--------------- NO! This will attempt to read the entire remaining part of the file into s3; since almost always what is wanted is the rest of the LINE, the use of \n is correct. Your example will cause a core dump if someone uses it to read in a magic cookie at the beginning of a file (something like the infamous #!). -- Brandon S. Allbery, moderator of comp.sources.misc and comp.binaries.ibm.pc {{harvard,mit-eddie}!necntc,well!hoptoad,sun!cwruecmp!hal}!ncoast!allbery ARPA: necntc!ncoast!allbery@harvard.harvard.edu Fido: 157/502 MCI: BALLBERY <>