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

sprintf

Hello!

I am trying to use sprintf, but get no result (C51, version 5.20).

char xdata command [80], i=100;
strcpy (command, "Hello!"); // now command contains "Hello!"
sprintf (command, "Test %d", i); // command has not changed
Why would sprintf not work?
Thank you for any help!
Holger

Parents
  • Why would sprintf not work?

    It's working. If you want to see the value 100 ( 64h 'd' ) you need to change the format string argument, %d means int, if you put %c it will work as expected because you are using a char data type.

    char xdata command [80], i=100;
    
    sprintf (command, "Test %c", i); // command has changed


    - Alex

Reply
  • Why would sprintf not work?

    It's working. If you want to see the value 100 ( 64h 'd' ) you need to change the format string argument, %d means int, if you put %c it will work as expected because you are using a char data type.

    char xdata command [80], i=100;
    
    sprintf (command, "Test %c", i); // command has changed


    - Alex

Children