Solved

ULARGE_INTEGER

Posted on 2000-03-02
6
1,288 Views
Last Modified: 2013-12-03
if I have two unsigned long values? How can i add them up together and reflec the total in a ULARGE_INTEGER variables

unsigned long a = 3333333333
unsigned long b = 3333333333
unsigned long c = a + b
                = 6666666666 - 4294967296
                = 2371699370
If I want to print out the total value of  ULARGE_INTEGER, which is 6666666666, how should my printf statement looks like?
0
Comment
Question by:zhenteng
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:Pacman
ID: 2576320
   ULARGE_INTEGER abc;
    unsigned long a = 3333333333;
    unsigned long b = 3333333333;

    abc.QuadPart = a;
    abc.QuadPart += b;
    sprintf(buf, "%I64d", abc);

0
 
LVL 9

Expert Comment

by:Pacman
ID: 2576344
PS: prefix "%I64" is microsoft specific
0
 
LVL 15

Accepted Solution

by:
NickRepin earned 100 total points
ID: 2578345
For MS VC 6.0

#include <stdio.h>

void main()
{
__int64 a = 3333333333 ;
__int64 b = 3333333333 ;
__int64 c=a+b;
printf("%I64d",c);
}
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

by:zhenteng
ID: 2578713
The sprintf statement doesn't seem to work though. I traced thru the code and found this error at the line when sprintf statement took place.

Total.QuadPart = Total.QuadPart/1000/1000;
dHD = Total.LowPart;
dHD = dHD/1000;
sprintf(oTemp.GetBuffer(10), "%.2g GB", dHD);

The error I got was:
Debug Error!
Program: C:\Personal\TestProg\TestProg.exe
DAMAGE: after Normal block (#135) at 0x00DB26F0

Whether I use %.2f or %.2e or %.2g, I still got the error.

Thank You
0
 

Author Comment

by:zhenteng
ID: 2578766
I just noticed it's caused by CString
0
 
LVL 9

Expert Comment

by:Pacman
ID: 2579364
zhenteng,

buf is char array:

char buf[100];

I don't know CString because I don't use MFC.
If you take this buffer it will work fine.
I'm using VC5.0.

Here again the complete example.


 ULARGE_INTEGER abc;
 unsigned long a = 3333333333;
 unsigned long b = 3333333333;
 char buf[100];

 abc.QuadPart = a;
 abc.QuadPart += b;
 abc.QuadPart = abc.QuadPart / 1024 / 1024;  // ... to GB
 sprintf(buf, "%I64d", abc);


If you want you can use __int64 instead of ULARGE_INTEGER (see NickRepin's comment).
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question