From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,80ae9f89712e54ee X-Google-Attributes: gidfee84,public X-Google-Thread: 1014db,80ae9f89712e54ee X-Google-Attributes: gid1014db,public From: norm@godel.une.edu.au (Norman Gaywood) Subject: Re: printf-problem Date: 1996/01/22 Message-ID: <4dv0pj$nh2@grivel.une.edu.au>#1/1 X-Deja-AN: 135990380 references: <4dj4g6$t9f@sunsystem5.informatik.tu-muenchen.de> <4dojc3$g2j@surz03fi.HRZ.Uni-Marburg.DE> organization: University of New England, NSW, Australia newsgroups: comp.unix.osf.osf1,comp.lang.c 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 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