Copy one file content into another file : Linux

First create a file named as file1 and write something into it.

#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
int main()
{
int n,m;
char buffer[50];
n = open ("file1", O_RDONLY);  // read only mode
m = open("file2" , O_CREAT | O_WRONLY,0777) ;  // write only mode
printf("Both files are open");
read(n,buffer,20);  // reading from file1 (n file descriptor )
write(m,buffer,20); // writing into file2
printf("Task completed ");
return 0;
}

Leave a comment