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
  • All work OK (compiled and simulated in dScope).

    But without explicitly typecasting of 'i' you get wrong result

    char xdata command [80], i=100;
    sprintf (command, "Test %d", (int) i); // command has "Test 100"
    sprintf (command, "Test %d", i); // command has "Test 25600"
    

    See advice of Mark Odell about 'integer promotion'.

Reply
  • All work OK (compiled and simulated in dScope).

    But without explicitly typecasting of 'i' you get wrong result

    char xdata command [80], i=100;
    sprintf (command, "Test %d", (int) i); // command has "Test 100"
    sprintf (command, "Test %d", i); // command has "Test 25600"
    

    See advice of Mark Odell about 'integer promotion'.

Children
No data