Tech Support Section Home Mekong Network Home
About This Site...
Mekong.Net Sites...
Recently Updated...
Recommended Links...
Contact Us...
Questions? Comments? Requests? Click here to contact us.

Format Specifiers for C

Back in the day, I used to occasionally trot out my faithful old copy of Borland C++ Version 5.02, and throw together a kludgy little program to cope with some obscure problem. However, I never learned C well, and I don't use it often enough to remember even the most basic stuff... such as how to tell the "printf" function what type of expression I want to display. I finally got tired of looking through the help to try to find the complete list, so I just threw together the following list, pulled from Tony Zhang's fine book Teach Yourself C in 24 Hours. (OK, there is no way in hell anyone learns C in 24 hours, but still... it's a good book.) And here is the list of available format specifiers:

%c     The character format specifier.
%d     The integer format specifier.
%i     The integer format specifier (same as %d).
%f     The floating-point format specifier.
%e     The scientific notation format specifier.
%E     The scientific notation format specifier.
%g     Uses %f or %e, whichever result is shorter.
%G     Uses %f or %E, whichever result is shorter.
%o     The unsigned octal format specifier.
%s     The string format specifier.
%u     The unsigned integer format specifier.
%x     The unsigned hexadecimal format specifier.
%X     The unsigned hexadecimal format specifier.
%p     Displays the corresponding argument that is a pointer.
%n     Records the number of characters written so far.
%%     Outputs a percent sign.

I don't understand what the hell all of these do. I also never understood the difference between %e and %E, or %x and %X, until a guy named Cary Wyman was kind enough to email an explanation: while %e and %x will display any letters in lowercase, %E and %X will display them in uppercase. Cary also explains that "%d is the normal specifier for integers; for input, slightly different formatting rules apply when you use % (eg, you don't write 32L to indicate that 32 is a long); for output, %i makes no difference." I still don't quite get that, but at this point I'd say chances are just about zero that I'll ever need to.

Oh, and since I sometimes forget this, too: let's say I want to compile a 16-bit console app, and I want to tell the compiler to put the .exe in my "code" directory. If my source code was called myapp.c, the syntax would be this:

bcc -nc:\bc5\code c:\bc5\code\myapp.c

Sadly, the word on the street is: the 64-bit versions of Windows will not support 16-bit applications. Sob! Who'd have thunk it? (Bonus points if you get that joke!) Anyway, it looks like my days of using my old little Borland C tools are numbered. Ah, progress marches on.