Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
Subject: Re: printf-problem
Date: 1996/01/17	[thread overview]
Message-ID: <ALUN.CHAMPION.96Jan17161824@g7240065.bridge.bst.bls.com> (raw)
In-Reply-To: 4dj4g6$t9f@sunsystem5.informatik.tu-muenchen.de

In article <4dj4g6$t9f@sunsystem5.informatik.tu-muenchen.de> wist@lam.mw.tu-muenchen.de (Henrik Wist) writes:

: long int zahl;   /* which is e.g. 10000500001 */
: printf("%d\n",zahl);      /* gives 1410565409, which is definitly wrong */

Though the FAQ goes into a lot of detail about printf and scanf, but it
sort of misses this one. The closes it gets is in the answer to 
"How can I convert numbers to strings (the opposite of atoi)?"
In the answer it says :- 
        You can obviously use sprintf() to convert long or floating-
        point numbers to strings as well (using %ld or %f).

I suppose the answer is there ;')

Anyway the answer is %d is the printf specifier for ints not longs
%ld is the printf specifier for longs. Man pages and/or almost any book
on 'C' could have told you this.

Regards

   -A.
-- 
| A.Champion                |



  reply	other threads:[~1996-01-17  5:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-01-17  5:00 printf-problem Henrik Wist
1996-01-17  5:00 ` Alun Champion [this message]
1996-01-17  5:00 ` printf-problem P.Bennett
1996-01-17  5:00   ` printf-problem The Amorphous Mass
1996-01-17  5:00 ` printf-problem Lawrence Kirby
1996-01-18  5:00   ` printf-problem Dik T. Winter
1996-01-18  5:00 ` printf-problem Henrik Wist
1996-01-19  5:00 ` printf-problem Achim Reeh
1996-01-22  5:00   ` printf-problem Norman Gaywood
  -- strict thread matches above, loose matches on Subject: below --
1996-01-17  5:00 printf-problem The Amorphous Mass
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox