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
  • Hi Alex,

    Thank you for your help. It is a bit hard to explain without listing a
    large amount of source code here.
    What I initialy did is I took a function I wrote using C166 that uses
    a bunch of sprintf commands, and copied it into my C51 source code.
    Now, my sprintf commands that work fine with C166 don't work with
    C51.
    Is there a major difference? I would have thought that's an ANSI
    command and it should work the same way in every C compiler version.

    After executing the line:

      sprintf (command, "Just a text");
    
    using C166, the value of command is: "Just a text".
    using C51, the value of command is still the same as before, and didn't
    get changed by sprintf.
    Same result with any possible format string in sprintf.
    Can there be something wrong with my C51 version?
    Thanks again for your time!
    Holger

Reply
  • Hi Alex,

    Thank you for your help. It is a bit hard to explain without listing a
    large amount of source code here.
    What I initialy did is I took a function I wrote using C166 that uses
    a bunch of sprintf commands, and copied it into my C51 source code.
    Now, my sprintf commands that work fine with C166 don't work with
    C51.
    Is there a major difference? I would have thought that's an ANSI
    command and it should work the same way in every C compiler version.

    After executing the line:

      sprintf (command, "Just a text");
    
    using C166, the value of command is: "Just a text".
    using C51, the value of command is still the same as before, and didn't
    get changed by sprintf.
    Same result with any possible format string in sprintf.
    Can there be something wrong with my C51 version?
    Thanks again for your time!
    Holger

Children