Computing.Net > Forums > Programming > printing a long long int with print

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

printing a long long int with print

Reply to Message Icon

Name: geohoffman49431
Date: March 2, 2006 at 15:46:32 Pacific
OS: XP PRO
CPU/Ram: 512 DDR 2700
Product: Generic
Comment:

Simple/stupid question but I cant seem to find the answer on google. I have a variable I want to print with printf. The variable is :

long long int var;

how do I print in both hex and decimal - the syntax should be something like:

printf("%<type> %<type>", var, var);

for a long long int it never seems to print the entire number - for instance if I use X for the type it will only print the first 8 hex numbers and not all 16.

If it matters this is compiled with gcc in a unix environment.



Sponsored Link
Ads by Google

Response Number 1
Name: Wolfbone
Date: March 3, 2006 at 01:58:27 Pacific
Reply:

If your libc is Gnu, 'info libc integer' in a terminal should get you this page:

http://www.gnu.org/software/libc/manual/html_node/Integer-Conversions.html#Integer-Conversions

printf("%LX %Ld",var,var) for example.


0

Response Number 2
Name: geohoffman49431
Date: March 3, 2006 at 07:36:38 Pacific
Reply:

Thank you for the reply. Im not sure what libc is (the linux equivalent to the win32 APIs?) - I run all my code over an ssh terminal from windows. I have to compile it on my universities server. Anyway I did finally find somewhere that %lld and %llX work. I had tried the %LX before and I think it should work but I keep getting segmentation errors when I use it on my schools server. No idea why.


0

Response Number 3
Name: anonproxy
Date: March 3, 2006 at 18:30:56 Pacific
Reply:

libc = c library

C has a standard library that almost every platform (hardware, OS, etc.) supports. A basic part of most OS's is the c library - most systems have C at the core of their runtime stack. Linux, for example, uses the very common GNU libc (glibc). Windows (last I checked) uses a Microsoft implementation. These are implementations of an ANSI standard. They may have their own extras or quirks and are generally tied to a compiler (e.g. windows has VSC++, Linux has gcc).

On top of libc the OS comes with highler level libs, like win32. You have a lot of options when you get to this application level though.



0

Response Number 4
Name: Wolfbone
Date: March 4, 2006 at 11:05:19 Pacific
Reply:

And if you really didn't even know what libc was before anonproxy's explanation, it would be a good idea to read some of the libc info pages, from the introduction onwards, and some of the gcc info pages.

Segmentation errors in small programs are almost always your own stupid fault ;-) and easily found and fixed. Even so, it's probably a good idea to learn to use a debugger such as gdb. There's a graphical front-end for it (and other debuggers) called ddd. If your university server has it, you should be able to run it and other graphical programs remotely, even on Windows.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: printing a long long int with print

IDL problem with a long variable www.computing.net/answers/programming/idl-problem-with-a-long-variable/13249.html

dos mode printing using crystal reports www.computing.net/answers/programming/dos-mode-printing-using-crystal-reports-/286.html

Excel VBA - printing sequential # www.computing.net/answers/programming/excel-vba-printing-sequential-/14781.html