when compiling my program with GCC I get the following warning:
format ‘%d’ expects type ‘int’, but argument 2 has type ‘long unsigned int
Now just by playing around I realize %lo fixes the warning. However I don’t really understand what I am doing.
Is there a naming convention to get the short form of a type? For example, int is %d, why??
Thanks!
What you’re doing is telling the
printffunction how to display the data that you provide following the format string. You’ll probably find that%lodoesn’t really print the results you expect — it prints the right data, but in octal (base 8) format.The “short form” is called a format specifier. There’s no convention that lets you derive the appropriate printf format specifier. You just have to look them up in an appropriate reference.