Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #include <fcntl.h>
  4.  
  5. #include <stdlib.h>
  6.  
  7. #include <unistd.h>
  8.  
  9. #include <string.h>
  10.  
  11.  
  12.  
  13.     int main()
  14.  
  15.         {
  16.  
  17.  
  18.  
  19.         int source_fd,char_read;
  20.  
  21.         char* path="/root/E2L/emp";     // file name
  22.  
  23.         char buf[128];
  24.  
  25.         memset(buf, 0 ,sizeof(buf));
  26.  
  27.  
  28.  
  29.  
  30.  
  31.             if ((source_fd = open(path, O_RDONLY)) < 0) {
  32.  
  33.                 perror("Open source failed:");
  34.  
  35.                 exit(2);
  36.  
  37.             }
  38.  
  39.  
  40.  
  41.             if((char_read = read(source_fd,buf,sizeof(buf)-1)) < 0){
  42.  
  43.                 perror("Read error :");
  44.  
  45.                 exit(2);
  46.  
  47.             }
  48.  
  49.  
  50.  
  51.             printf("Characters read = %d \n",char_read);
  52.  
  53.             printf("%s\n",buf);
  54.  
  55.  
  56.  
  57.  
  58.  
  59.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement