HAR1F

Untitled

May 24th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <fcntl.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. int main()
  7. {
  8.    int     fd;
  9.    size_t  size;
  10.    char    string[] = "Hello, world!";
  11.  
  12.    if((fd = open("myfile", O_WRONLY | O_CREAT, 0666)) < 0){
  13.      printf("Can\'t open file\n");
  14.      exit(-1);
  15.    }
  16.  
  17.    size = write(fd, string, 14);
  18.  
  19.    if(size != 14){
  20.      printf("Can\'t write all string\n");
  21.      exit(-1);
  22.    }
  23.  
  24.    if(close(fd) < 0){
  25.      printf("Can\'t close file\n");
  26.    }
  27.  
  28.    return 0;
  29. }
Add Comment
Please, Sign In to add comment