Talking about scanf (was Re: What's so bad about scanf anyway???)
Larry Jones
scjones at thor.UUCP
Sat Nov 17 10:29:01 AEST 1990
In article <960 at mwtech.UUCP>, martin at mwtech.UUCP (Martin Weitzel) writes:
> BTW: Recently there occured a problem, to which I couldn't find an
> immediate solution. Take the following program fragment:
>
> #define X 100
> char word[X+1]; int z;
>
> 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.
Yes. I never did understand why printf allowed "*" for run-time
specification of field width and precision, but scanf usurped "*"
for assignment suppression and so doesn't support run-time field
widths.
Any historians know how this came to be?
----
Larry Jones UUCP: uunet!sdrc!thor!scjones
SDRC scjones at thor.UUCP
2000 Eastman Dr. BIX: ltl
Milford, OH 45150-2789 AT&T: (513) 576-2070
Physical education is what you learn from having your face in
someone's armpit right before lunch. -- Calvin
More information about the Comp.lang.c
mailing list