+ 2
Write a C program that makes a copy of a file using standard I/O, and system calls
4 ответов
0
this is not a question this is a statement, is there a question you have?
0
Yeah Beth u should write program that makes a copy of a file using system calls in files
0
Hi Keerthana Vema,
That was still not a question. Please be respectful of the intended uses of the Q&A area.
https://www.sololearn.com/discuss/1316935/?ref=app
0
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int f1, f2;
char buff[50];
long int n;
if(((f1 = open(argv[1], O_RDONLY)) == -1 || ((f2=open(argv[2], O_CREAT | O_WRONLY | O_TRUNC,
0700))== 1)))
{
perror("problem in file");
exit(1);
}
while((n=read(f1, buff, 50))>0)
if(write(f2, buff, n)!=n)
{
perror("problem in writing");
exit(3);
}
if(n==-1)
{
perror("problem in reading");
exit(2);
}
close(f2);
exit(0);
}
OUTPUT:
Step1: Create an empty file dest.txt
Step2: save the program as filecopy.c
root@kali:~# gcc filecopy.c
root@kali:~# ./a.out filecopy.c dest.txt
step5: open the file dest.txt and see if content is copied or not.