int open file in c

Solutions on MaxInterview for int open file in c by the best coders in the world

showing results for - "int open file in c"
Andrea
13 Jun 2020
1#include <unistd.h>
2#include <fcntl.h>
3 
4int main()
5{
6    int filedesc = open("testfile.txt", O_WRONLY | O_APPEND);
7    if(filedesc < 0)
8        return 1;
9 
10    if(write(filedesc,"This will be output to testfile.txt\n", 36) != 36)
11    {
12        write(2,"There was an error writing to testfile.txt\n");    // strictly not an error, it is allowable for fewer characters than requested to be written.
13        return 1;
14    }
15 
16    return 0;
17}
18