| ||||||||
Technical Support Support Resources Product Information | C51: PROBLEMS USING PRINTFInformation in this article applies to:
QUESTIONI can get the printf command to work with integers but not long integers or 8-bit integers. Why? ANSWERYou must use the optional characters B or b and L or l immediately preceding the type character to respectively specify char or long versions of the integer types d, i ,u, o, x and X. The following printf correctly prints 1, 2, and 3 as integers:
printf ("%d %d %d", (int) 1, (int) 2, (int) 3);
The following printf correctly prints 1, 2, and 3 as long integers:
printf ("%Ld %Ld %Ld", 1L, 2L, 3L);
The following printf correctly prints 1, 2, and 3 as chars:
printf ("%Bd %Bd %Bd", (char) 1, (char) 2, (char) 3);
The type casts on the numeric constants are important because they specify the number of bytes required for each numeric constant. FORUM THREADSThe following Discussion Forum threads may provide information related to this topic. Last Reviewed: Wednesday, May 05, 2004 | |||||||
| ||||||||