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

what will happen if printf() function is used ?

Dear All,

In my coding , by mistaken i used printf() function instead of sprintf()....
but my code compile ....but not running....

but after replacing sprintf() function ....my code is working fine.

Can any explain be what happen?

Thanks in Advance.

Parents
  • 1) You may not have configured your code to know where to send data from printf(). Does printf() work in other parts of your code?

    2) printf() takes a formatting string as first argument. sprintf() takes a destination buffer as first argument and the formatting string as second argument. How fun for printf() to get a buffer of random content as formatting string.

    3) printf() wants to emit data, which means that printf() can require a lot of time while waiting for a serial port to consume the data. This may break a program that needs the call to be quick. sprintf() don't need to synchronize with any I/O - it just leaves the result in a buffer.

Reply
  • 1) You may not have configured your code to know where to send data from printf(). Does printf() work in other parts of your code?

    2) printf() takes a formatting string as first argument. sprintf() takes a destination buffer as first argument and the formatting string as second argument. How fun for printf() to get a buffer of random content as formatting string.

    3) printf() wants to emit data, which means that printf() can require a lot of time while waiting for a serial port to consume the data. This may break a program that needs the call to be quick. sprintf() don't need to synchronize with any I/O - it just leaves the result in a buffer.

Children
No data