Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am using QuerryPerformanceCounter to measure performance of the Application. It takes __int64 as a out parameter. I need to write it in the file. How to do it. ??
Posted
Comments
Emilio Garavaglia 19-Jul-11 5:00am    
It depends on what you're going to use that file. It can be a binary dump, a textual form, a compressed encode...
Elaborate much more your question
PrafullaVedante 19-Jul-11 5:11am    
Hie ...
I got the answer i am using %I64d in fprintf.

Thanks anyways.

LARGE_INTEGER performanceCount;
if (QueryPerformanceCounter(&performanceCount))
{
    fwrite(&performanceCount, sizeof performanceCount, 1, fileStream);
}

or similar.
 
Share this answer
 
Comments
Espen Harlinn 19-Jul-11 5:11am    
My 5 - btw: the parenthesis for the sizeof operator is missing ...
Richard MacCutchan 19-Jul-11 5:32am    
parenthesis for the sizeof operator is missing
No, they are not necessary in the above case; try it out. See also here
PrafullaVedante 19-Jul-11 5:11am    
I got the answer i am using %I64d in fprintf.
Richard MacCutchan 19-Jul-11 5:33am    
Maybe if you had explained that you wanted to print the number, rather than write in a file, we might have given a better answer.
PrafullaVedante 22-Jul-11 3:36am    
Sorry boss ;) :) Thanks anyways
Hi,
FILE *fptr = NULL;
 if(fopen_s(&fptr,"Sample.txt","w") != 0){
     cout << "Could not open file";
 }
 __int64 a=10;
     QueryPerformanceCounter((LARGE_INTEGER*)&a);
 char    b[255];
 sprintf_s(b,255,"%d",a);
 fprintf_s(fptr,"%s",b);
 fclose(fptr);


The code above writes the __int64 to a file,are you facing any issues in writing __int64 which is returned by QueryPerformanceCounter?
 
Share this answer
 
Comments
PrafullaVedante 19-Jul-11 5:11am    
I got the answer i am using %I64d in fprintf.
hakz.code 19-Jul-11 5:20am    
Ok..so %I64 format specifier needs to be used in case of __int64.Thank you I actually forgot it in my code.
Richard MacCutchan 19-Jul-11 5:36am    
This is incorrect, the %d format selector will not print a 64 bit number. And why convert the integer to a string and then use fprintf() to write the string to the file? Just use fprintf() direct from integer to the file.
hakz.code 19-Jul-11 6:08am    
Yes!agreed

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900