Answer the question
In order to leave comments, you need to log in
Why am I getting 2 extra zeros?
I'm trying to display an 8 byte array on the LCD, I expected to get "0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF" after executing this program,
char * read_rom(){
unsigned int i;
charch[8];
char ch1[1];
for(i=0;i<=8;i++){
temporary[i]=0xFFFF;//RX();
sprintf(ch1, "0x%X", temporary[i]);
lcd_display(ch1);
}
return temporary;
}
but as a result I get: "0xFF000xFF000xFF000xFF000xFF000xFF000xFF000xFF00"
Explain to the incompetent why?
Answer the question
In order to leave comments, you need to log in
Two bugs at once:
Extra loop iteration:
i or should be <8 or <=7
Length modifier not used:
Fix:sprintf (ch1, "0x%2X", temporary[i]);
You cram 16 unsigned into an 8 bit signed char and output a signed char
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question