_int64 and sprintf  
Author Message
NaveenG





PostPosted: Common Language Runtime, _int64 and sprintf Top

Hi,

I have the following program:

int main()
{
_int64 number = 0x12345678123456;
usigned char string2[100] = {'\0'};

sprintf(string2, "_%016lx_", number);
printf("%s\n", string2);
}

This prints only the first 4 bytes:

_0000000012345678_

My compiler version is:

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86

Can anyone tell why only 4 bytes are printed in the string Is this the limitation of sprintf

Thanks,

Naveen.



.NET Development19  
 
 
Mike Danes





PostPosted: Common Language Runtime, _int64 and sprintf Top

You need the ll or I64 size prefix instead of just l:

 sprintf(string2, "_%016llx_", number);

 sprintf(string2, "_%016I64x_", number);

See this documentation page for information about various size prefixes for sprintf.

http://msdn2.microsoft.com/en-us/library/tcxf1dw6.aspx

 


 
 
NaveenG





PostPosted: Common Language Runtime, _int64 and sprintf Top

I had used ll also. It hadnt worked, it was the same output with ll:

_0000000012345678_

But, I64 worked! Thanks for the link.


 
 
Mike Danes





PostPosted: Common Language Runtime, _int64 and sprintf Top

Ah, yes. ll does not work with VC++ 2003. It is new to VC++ 2005.