Imbeding varables in printf()
All right so I was working on my sdl app and I seem to have forgotten, how to imbed varables into printf() for the purposes of debugging. I checked my c++ manual and it just gives jibberish. Any help would be appreciated.
-shadow
-shadow
Here are a few example printf statements that should help you out.
Remember, you can prefix %d or %u with l to make it long (%ld = long int, %lu = unsigned long int).
- Andy Oxfeld
/* Embedded int */printf("%d", anint);/* Embedded unsinged int */printf("%u", anunsignedint);/* Embedded float */printf("%f", afloat);/* More complicated float: max 3 decimal places */printf("%.3f", afloat);/* Embedded char */printf("%c", achar);/* Embedded string */printf("%s", astring);/* More complicated string: max 10 characters*/printf("%10s", astring);
Remember, you can prefix %d or %u with l to make it long (%ld = long int, %lu = unsigned long int).
- Andy Oxfeld
You can also prefix ''f'' with an ''l'' (%lf) for doubles, and ''d'' and ''u'' can be prefixed with an ''s'' for shorts and unsigned shorts.
For floats and doubles, unless you want quite a few digits after the decimal point, you should specify the number of digits.
"%.4lf" for instance, will work with a double, but will only show 4 decimal places.
-Neophyte
For floats and doubles, unless you want quite a few digits after the decimal point, you should specify the number of digits.
"%.4lf" for instance, will work with a double, but will only show 4 decimal places.
-Neophyte
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement