I run into a problem using enum datatype with printf statement. The folloing code works with Viusal C but does not work with KEIL compiler --- printf statement prints out the wrong value. Could somebody in this forum tell me what I did wrong here? --- here is the test code
enum MONTHS {JAN=1,FEB,MAR,APR,MAY,JUN,JUL, AUG,SEP,OCT,NOV,DEC} birthday; void main(void) { birthday = NOV; printf("\n\r\ My birthday = %d", birthday); }
Please review: http://www.keil.com/support/man/docs/c51/c51_ap_1bytescalar.htm and http://www.keil.com/support/man/docs/c51/c51_printf.htm Then decide whether you want:
printf("\n\r\ My birthday = %d", (int)birthday);
printf("\n\r\ My birthday = %bd", birthday);
Hi Dan, It works now. Thank you for your help. JIMMY