I am having following code. output of second %d in sprintf is always shown as zero. I think i am specifying wrong specifiers. Can any one help me in getting write string with right values. And this has to achieved in posix standard. Thanks for inputs
void main() {
unsigned _int64 dbFileSize = 99;
unsigned _int64 fileSize = 100;
char buf[128];
memset(buf, 0x00, 128);
sprintf(buf, "\nOD DB File Size = %d bytes \t XML file size = %d bytes", fileSize, dbFileSize);
printf("The string is %s ", buf);
}
Output:
The string is
OD DB File Size = 100 bytes XML file size = 0 bytes
I don't know what POSIX has to say about this, but this is nicely handled by core C99:
If your compiler isn't C99 compliant, get a different compiler. (Yes, I'm looking at you, Visual Studio.)
PS: If you are worried about portability, don't use
%lld
. That's forlong long
, but there are no guarantees thatlong long
actually is the same as_int64
(POSIX) orint64_t
(C99).Edit: Mea culpa - I more or less brainlessly "search & replace"d the
_int64
withint64_t
without really looking at what I am doing. Thanks for the comments pointing out that it'suint64_t
, notunsigned int64_t
. Corrected.