Talking about scanf (was Re: What's so bad about scanf anyway???)

Avery Colter avery at netcom.UUCP
Thu Nov 22 21:19:58 AEST 1990


martin at 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"



More information about the Comp.lang.c mailing list