473,471 Members | 1,981 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to print 64 bit integer using sprintf() family

2 New Member
I have a need to print 64 bit integer in Windows and UNIX environments.

Code Snipet:

unsigned __int64 mNumRowsRead=1234567890123456;

sprintf(buf, "%d row(s) read", mNumRowsRead);
sprintf(buf, "%s row(s) read", mNumRowsRead);
sprintf_s(buf, "%d row(s) read", mNumRowsRead);
itoa(mNumRowsRead,buff2,10);
cout << buff2 << endl;
sprintf_s(buf, "%s row(s) read", buff2);

First sprintf converted the 64 bit integer to 32 bits. The out interger is 1015724736 instead of 1234567890123456.
Second sprintf throws exception.
Third sprintf_s behavior like first one.
Last sprintf_s throws exception without itoa(). With itoa() the number was truncated. itoa() must not be able to handle 64 bit integer as expected. So, do we have 64 bit version of itoa()?? Or how do I print a 64 bit integer as part of a string. Thanks for the help.
Oct 1 '07 #1
3 24777
Banfa
9,065 Recognized Expert Moderator Expert
On windows you need to let sprintf know it is a 64 bit integer using the I64 prefix
Expand|Select|Wrap|Line Numbers
  1. sprintf(buf, "%I64d row(s) read", mNumRowsRead);
  2.  
more information here
Oct 1 '07 #2
jannlin
2 New Member
On windows you need to let sprintf know it is a 64 bit integer using the I64 prefix
Expand|Select|Wrap|Line Numbers
  1. sprintf(buf, "%I64d row(s) read", mNumRowsRead);
  2.  
more information here
Thanks for the help. I suppose I need to use I64u for unsigned 64 bit integer. Is I64d for signed 64 bit integer? Thanks.
Oct 3 '07 #3
Banfa
9,065 Recognized Expert Moderator Expert
Thanks for the help. I suppose I need to use I64u for unsigned 64 bit integer. Is I64d for signed 64 bit integer? Thanks.
That's correct, it's all in the link I provided.
Oct 3 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Venkat Venkataraju | last post by:
Hi All I'm having problems printing a string with a % char. Here is the code line = sprintf("<table width=100% id=%s>\n", $table_id); I'm getting an not enough parameter error. The % for the...
0
by: Joshua Burvill | last post by:
Hello, I am trying to print something to a print server using the following function but I get errors, does anyone have any pointers? Rgds, Josh Traceback (most recent call last): File...
16
by: John Baker | last post by:
HI; I feel like a fool..I put CUTE FTP in my last request for help --it should have been CUTE PDF! I have FTP on my mind because I have been working on a web based application, and somehow my...
3
by: jt | last post by:
Here is my code: unsigned long listenip; short tlen; sprintf(tmp,"len:%x listenip:%x",htonl(tlen),listenip); If the value on "tlen" is less than 2 bytes and the value on "listenip" is...
12
by: babak | last post by:
Hi everyone I want to format a string (using sprintf) and put it in a messagebox but however I try to do it, it doesn't seem to work. Here is an example sample of what i try to do: char msg;...
7
by: wenmang | last post by:
what is format for sprintf to convert long long integer (64 bits) to string?
3
by: Susan Rice | last post by:
How can I rewrite this code to avoid the possibility of a buffer overflow? sprintf(errbuf, "%s\nError is: %u: %s\n", errmsg, dwErrCode, s ); Here: errmsg = a string dwErrCode = a number s =...
7
by: markww | last post by:
Hi, Is there a way to use sprintf() to put a number of zeros before a number, like: sprintf(szBuffer, "%i", 7); "007"; I have a list of numbers I want to sort that are text based, and I...
15
by: ab12 | last post by:
I am writing in C. I want to reverse the input integer using recursion so if the input is 456, the output should be 654. it only needs to work with positive numbers. I've already written this...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.