Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!olivea!oliveb!amdahl!netcom!avery From: avery@netcom.UUCP (Avery Colter) Newsgroups: comp.lang.c Subject: Re: Talking about scanf (was Re: What's so bad about scanf anyway???) Message-ID: <17294@netcom.UUCP> Date: 22 Nov 90 10:19:58 GMT References: <16582@netcom.UUCP> <960@mwtech.UUCP> Organization: Netcom- The Bay Area's Public Access Unix System {408 241-9760 guest} Lines: 26 martin@mwtech.UUCP (Martin Weitzel) writes: > scanf("%100[^:]:%d", word, &z); > ^^^----------------------- I'd rather want X here; still > better were `(sizeof word) - 1', so that I could ommit > the #define for X completly >What I could do is dynamically (at runtime) construct an appropriate >format specification. But IMHO this more a work-around than an elegant >solution to the problem. It may be the only way unfortunately, unless you have some interesting preprocessor at your disposal. How about just defining a string and an unsigned, uhh, lessee, assign X to the unsigned, then make sscanf(string," %u",&uns.int), and then a couple of strcats to put the rest of the format string around it, and voilla. What is inelegant about this? Or am I dealing with people who think that code has to be a candidate for the SI Swimsuit Issue to be called elegant? -- Avery Ray Colter {apple|claris}!netcom!avery {decwrl|mips|sgi}!btr!elfcat (415) 839-4567 "I feel love has got to come on and I want it: Something big and lovely!" - The B-52s, "Channel Z"