Advertisement
montimaj

AS2_3

Aug 14th, 2015
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include<sys/file.h>
  2. #include<sys/types.h>
  3. #include<sys/stat.h>
  4. #include<unistd.h>
  5. #include<stdio.h>
  6. int main()
  7. {
  8.   char f1[30],f2[30],t[100];
  9.   int fd,s1,s2;
  10.   printf("Enter existing file name: ");
  11.   scanf("%s",f1);
  12.   printf("Enter new file name: ");
  13.   scanf("%s",f2);
  14.   fd=open(f1,O_RDONLY,S_IRUSR);
  15.   if(fd==-1)
  16.     return 1;
  17.   s1=read(fd,t,100);
  18.   close(fd);
  19.   fd=creat(f2,S_IWUSR);
  20.   s2=write(fd,t,s1);
  21.   close(fd);
  22.   if(s1==s2)
  23.     printf("Size of both files= %d bytes\n",s1);
  24.   else
  25.     printf("Size mismatch\n");  
  26.   return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement