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!

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 10 月 25 日

2 投票

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

1 件のコメント

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

サインインしてコメントする。

その他の回答 (1 件)

Sachin Ganjare
Sachin Ganjare 2012 年 10 月 25 日

1 投票

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

4 件のコメント

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

サインインしてコメントする。

カテゴリ

タグ

質問済み:

2012 年 10 月 25 日

コメント済み:

2017 年 1 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by