0

There are differences between open() and fopen() function. One is system call and other is library function. I try to figure out what is the application of these two function but I found nothing useful. Can you give some scenarios where to use open() and where fopen() should be used?

Amit
  • 81
  • 5

2 Answers2

2

Sometimes you need a file descriptor. open() gives you one. Sometimes you need a FILE*, in which case use fopen(). You can always turn your FILE* into a file descriptor via fileno(), whereas the opposite transformation is not really supported. It mostly depends on what downstream functions you intend to call with the file handle.

honk
  • 7,217
  • 11
  • 62
  • 65
John Zwinck
  • 207,363
  • 31
  • 261
  • 371
0

open() will return the file descriptor. We overwrite the file, while using the fopen() we cannot overwrite the file. We use the file descriptor for reading and writing using the other functions like read() write() etc. But in fopen() it will return file descriptor we have to use fprintf() to write to the file stream. sscanf() to read from the stream.

Q_SaD
  • 345
  • 1
  • 11