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.
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