This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

printf statement not giving the required string out.

Hi All
i want following string of bytes to be send by the CPU 80C51RD2 serial port:0xba,0x02,0x01,0xb9
statement:

printf("%c%c%c%c",stxi,select_lnth,select_cmd_char,select_bcc); 
output:0xba,0x02,0x01

why 0xb9 is missing ?

i have tried a long cut method to overcome this
unsigned int loop;
unsigned char buf[4]; 
sprintf(buf,"%c%c%c%c",stxi,select_lnth,select_cmd_char,select_bcc);
for(loop=0;loop<=4;loop++)
  printf("%c",buf[loop]); 
Above for statement should have worked with condition "loop<=3",but again last byte was missing.By giving "loop<=4" i got all required bytes.

why "for loop" terminating condition have to be kept at " <=4 " ,when it should have worked with " <=3 " ?

Thanks in advance

Parents Reply Children
No data