Good evening, experts!
I have question regarding file control and file descriptors using posix system calls
I've got how to copy one file to another from start, but how could i modify the programme to copy it in reverse order? Source file should have read access and destination file read write execute. I have to use file control libraries.
for example
Code:FILE A File B should be |---------| |----------| |ABCDEF | |FEDCBA | |---------| |----------|
I've tried to modify using lseek, but it does not giving me any result.
Could someone assist me pleaseCode:#include<stdlib.h> #include<stdio.h> #include<fcntl.h> #include<string.h> #include<sys/stat.h> #include<unistd.h> int main(int argc, char *argv[]) { int source, dest, n; char buf; if (argc!=3) { fprintf(stderr,"usage %s <source> <dest>",argv[0]); exit(-1); } if ((source=open(argv[1], 0400))<0){ fprintf(stderr,"error source"); exit(-1); } if ((dest=creat(argv[2],0700))<0){ fprintf(stderr,"error dest"); exit(-1); } if ((lseek=(source,1,SEEK_END))<0) perror("lseek"); while ((n=read(source,&buf,1))!=0) write(dest,&buf,1); write(STDOUT_FILENO,"OK",2); close(source); close(dest); return 0; }



1Likes
LinkBack URL
About LinkBacks


