There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer audio black screen boot bsod computer connection crash css dell display driver drivers email error ethernet excel explorer firefox firefox 3 game hard drive internet internet explorer itunes laptop lcd linux malware network networking nvidia outlook outlook 2003 outlook express partition printer problem router slow software sound trojan usb video virus vista windows windows xp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Solved: printf() Number Display Format


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
pcpro17's Avatar
Senior Member with 245 posts.
 
Join Date: Oct 2006
Location: Wisconsin, USA
Experience: Advanced
20-Dec-2006, 11:58 AM #1
Exclamation Solved: printf() Number Display Format
Hello. I'm trying to use printf to display 64-bit numbers (unsigned long long). The problem is it keeps giving me negative numbers (when using %d or %e) or they sometimes seem too small (when using %u). Here is a snippet of my code, and following it is the results it prints:
Code:
   printf( "Time1 ................. %e cycles\n", t1 );
   printf( "Time2 ................. %e cycles\n", t2 );
   printf( "Time2 - Time1 ......... %e cycles\n", time_passed );
Code:
Time1 ................. 7.488818e-309 cycles
Time2 ................. 7.488942e-309 cycles
Time2 - Time1 ......... 1.244329e-313 cycles
Is there another format specifier, or another print funciton, I should be using? It seems to work okay when I use the %x with it broken into two 32-bit numbers (unsigned long), but I need to work with it as a 64-bit number because I perform math on it for benchmarking purposes.

Thanks.
IMM's Avatar
IMM IMM is offline IMM is authorized to help remove malware.
Distinguished Member with 3,160 posts.
 
Join Date: Feb 2002
20-Dec-2006, 02:15 PM #2
It's a bit compiler dependent - but should be either %ld or %lld I think

---edit
whoops - just reread this and you probably want %llu ?
see http://unixhelp.ed.ac.uk/CGI/man-cgi?sprintf+3

Last edited by IMM : 20-Dec-2006 02:32 PM.
pcpro17's Avatar
Senior Member with 245 posts.
 
Join Date: Oct 2006
Location: Wisconsin, USA
Experience: Advanced
20-Dec-2006, 03:20 PM #3
Quote:
Originally Posted by IMM
It's a bit compiler dependent - but should be either %ld or %lld I think

---edit
whoops - just reread this and you probably want %llu ?
see http://unixhelp.ed.ac.uk/CGI/man-cgi?sprintf+3
Thanks, IMM! That did the trick!
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:10 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.