Bad file descriptor

后端 未结 3 871
旧时难觅i
旧时难觅i 2021-02-18 16:55

I\'m learning about file descriptors and I wrote this code:

#include 
#include 
#include 
#include          


        
3条回答
  •  花落未央
    2021-02-18 16:55

    According to the open(2) man page:

    The argument flags must include one of the following access modes: O_RDONLY, O_WRONLY, or O_RDWR.

    So yes, as suggested by others, please change your open to open("output", O_CREAT|O_WRONLY, 0777));. Use O_RDWR if you need to read from the file. You may also want O_TRUNC -- see the man page for details.

提交回复
热议问题