From: norm@godel.une.edu.au (Norman Gaywood)
Subject: Re: printf-problem
Date: 1996/01/22 [thread overview]
Message-ID: <4dv0pj$nh2@grivel.une.edu.au> (raw)
In-Reply-To: 4dojc3$g2j@surz03fi.HRZ.Uni-Marburg.DE
reeh@bunsen.HRZ.Uni-Marburg.DE (Achim Reeh) writes:
>Henrik Wist (wist@lam.mw.tu-muenchen.de) wrote:
>: Problem:
>: long int zahl; /* which is e.g. 10000500001 */
>: printf("%d\n",zahl); /* gives 1410565409, which is definitly wrong */
>Solution:
> printf("%ld\n",zahl); /* gives 10000500001 */
> ^^^
>%ld is the format specifier for long int output. long ints are 64 bit
>under DEC Unix and DEC C. ints (format %d) have only 32 bit.
OK, what about this one:
-------------------------------Cut----------------------
cat > sprintfbug.c
#include <stdio.h>
main()
{
static char buff[20] = "!!!!!";
int width = 4;
int lprecision = 0;
double val = 10.0;
sprintf( buff,"%*.*f", width, lprecision, val);
printf( ":%s:\n", buff );
}
^D
% cc -o sprintfbug sprintfbug.c
% sprintfbug
: 10!:
% uname -a
OSF1 metz.une.edu.au V3.2 17 alpha
-------------------------------Cut----------------------
The output should be:
: 10:
I found this while trying to get the sc spreadsheet working correctly.
This is not a problem in OSF 2.0
--
Norman Gaywood. Department of Mathematics, Statistics and Computing Science.
University of New England, Armidale, NSW 2351, Australia.
Internet: norm@godel.une.edu.au, phone: +61 67 732412, fax: +61 67 733312
next prev parent reply other threads:[~1996-01-22 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 ` printf-problem P.Bennett
1996-01-17 5:00 ` printf-problem The Amorphous Mass
1996-01-17 5:00 ` printf-problem Alun Champion
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 ` Norman Gaywood [this message]
-- 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