Difference between fprintf and fwrite?

Hello, I am using a serial communication and I want to send some data. I was wondering what is the actual difference between the fprintf and fwrite function? Thanks!

 Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 25 Okt. 2012

2 Stimmen

  • fprintf, write data to text file
  • fwrite, write data to binary file

1 Kommentar

David J. Mack
David J. Mack am 18 Jan. 2017
To be really precise, fprintf writes data in text, fwrite in binary format, but both functions can write to the same (mixed-type) file.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Sachin Ganjare
Sachin Ganjare am 25 Okt. 2012

1 Stimme

fprintf blocks the command line to execute other commands while the data is getting transferred while fwrite doesn't.

4 Kommentare

Ivana
Ivana am 25 Okt. 2012
Ok, so what if I want the program to run as fast as possible? Which one shall I use then?
Sachin Ganjare
Sachin Ganjare am 25 Okt. 2012
fprintf() is slow, because it does formatting. Writing one character at a time is slow in any case.
Ivana
Ivana am 25 Okt. 2012
Thanks!!! :)

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by