Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.

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.

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.

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.

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.

![]() |
![]() |
![]() |

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