Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!lll-winken!uunet!sdrc!thor!scjones From: scjones@thor.UUCP (Larry Jones) Newsgroups: comp.lang.c Subject: Re: Talking about scanf (was Re: What's so bad about scanf anyway???) Message-ID: <206@thor.UUCP> Date: 16 Nov 90 23:29:01 GMT References: <16582@netcom.UUCP> <960@mwtech.UUCP> Organization: SDRC, Cincinnati Lines: 29 In article <960@mwtech.UUCP>, martin@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@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