Path: utzoo!attcan!uunet!rufus!corvair.almaden.ibm.com!ebm From: ebm@corvair.almaden.ibm.com (Eli Messinger) Newsgroups: comp.lang.c Subject: scanf() question answered Message-ID: <273@rufus.UUCP> Date: 10 Oct 90 20:01:01 GMT Sender: news@rufus.UUCP Reply-To: ebm@ibm.com Organization: Pandora's Box Lines: 17 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@ibm.com / UUCP: ..!uunet!ibmarc!ebm / BITNET: ebm@almaden