Topic: FAQ? Syntax of scanf format codes.
Author: alistair@ichthya.demon.co.uk (Alistair Bell)
Date: Thu, 3 Mar 1994 10:19:44 +0000 Raw View
In article <1994Mar4.005059.19748@nchud5.nchu.edu.tw> yclee@PROBLEM_WITH_INEWS_GATEWAY_FILE writes:
>Table c.9 "scanf variations and what they do", listed something like this:
>
>Type Input T Address Type
>d integer int *
>D long integer long *
>.. ... ... [codes for integral types are similar]
>
>I have found that Borland C++ V 3.1 (1992) only supports integral code
>variations (i/I, d/D, o/O, x/X, u/U), but none on those of floating points'.
>
>And Microsoft MSC v7.0 supports u/U variation.
>
>Also, in the "The C Standard Library" (1991?) by Plauger, lists nothing about
>any variations on the capital one referring to the longer objects.
>
>Are these format codes correct, to the latest ANSI standard?
>
The short answer is NO! I came up against this problem with our compiler (Turbo
C/C++ v.1) where I was sscanf'ing %02X into an int and wondering why I was
getting memory corruption.
According to ANSI Classic 4.9.6.2 (or at least the late draft I have), the only
capital specifiers defined are E, G and X, and they behave exactly the same as
e, g and x. So at least in these cases your library is broken and you should
complain. (We haven't bothered because our compiler is back-level anyway. I've
no idea whether they've fixed it in version 2 or version 3.)
If you want to scanf a long, use %ld or equivalent.
--
Alistair Bell, | Home address:
Brown's Operating System Services, | Alistair Bell,
St. Agnes House, | C.U.M.,
Cresswell Park, | 43 Old Jamaica Road,
Blackheath, | Bermondsey,
London | London
SE3 9RD. | SE16 4TE.
Tel. +44 81-852 3299. | Tel. +44 71-237 6224.
Email: alistair@ichthya.demon.co.uk
I neither speak for Brown's, C.U.M., Demon, nor anyone else!
Author: rtrigg@crl.com (Roger Trigg)
Date: 3 Mar 1994 02:23:54 -0800 Raw View
yclee@PROBLEM_WITH_INEWS_GATEWAY_FILE wrote:
: I have received this book by Miller and Quilici called "Joy of C" (1993).
: In it's appendix c, Library Details,
: Table c.9 "scanf variations and what they do", listed something like this:
: Type Input T Address Type
: d integer int *
: D long integer long *
: .. ... ... [codes for integral types are similar]
: e floating point float * \
: E " double * | <- No reference.
: f floating point float * |
: F " double * /
: I have found that Borland C++ V 3.1 (1992) only supports integral code
: variations (i/I, d/D, o/O, x/X, u/U), but none on those of floating points'.
: And Microsoft MSC v7.0 supports u/U variation.
: Also, in the "The C Standard Library" (1991?) by Plauger, lists nothing about
: any variations on the capital one referring to the longer objects.
: Are these format codes correct, to the latest ANSI standard?
: Any help would be appreciated.
: Thanks in advance.
: YC, Lee
: email: me.nchu.edu.tw
y py a b s n & b han h C b I O) n y m n ns
E, , and X E and nd a h n s n n a n s
ap a z d, X nd a s h d g s a h va u a ap a z d
g F) u a m s d n y h ad ng n p ng d u s
y u us ap a z d v s ns h ma sp s ayb y u
d n a , bu y u m ssag s ms nd a ha y u d )
R g T gg gg@ m)
Author: yclee@PROBLEM_WITH_INEWS_GATEWAY_FILE ()
Date: Fri, 4 Mar 1994 00:50:59 GMT Raw View
I have received this book by Miller and Quilici called "Joy of C" (1993).
In it's appendix c, Library Details,
Table c.9 "scanf variations and what they do", listed something like this:
Type Input T Address Type
d integer int *
D long integer long *
.. ... ... [codes for integral types are similar]
e floating point float * \
E " double * | <- No reference.
f floating point float * |
F " double * /
I have found that Borland C++ V 3.1 (1992) only supports integral code
variations (i/I, d/D, o/O, x/X, u/U), but none on those of floating points'.
And Microsoft MSC v7.0 supports u/U variation.
Also, in the "The C Standard Library" (1991?) by Plauger, lists nothing about
any variations on the capital one referring to the longer objects.
Are these format codes correct, to the latest ANSI standard?
Any help would be appreciated.
Thanks in advance.
YC, Lee
email: me.nchu.edu.tw