Hi ppl
Got to use lseek function in this program below... Program is simply copying file (that already exist). I wanned to copy the existing file with the chars from the end of file for example: Sorce_File.txt contains:"1 2 3" after copy Target_File.txt contains:"3 2 1"
I'm pretty sure it's simple problem but couldn't find out since 2 days how to do it
#include <fcntl.h>
#include <stdio.h>
#define MAX 512
int main(int argc, char* argv[]){
char buf[MAX];
int desc_sorc, desc_targ;
int lbajt;
if (argc<3){
argv[0];
exit(1);
}
desc_sorc = open(argv[1], O_RDONLY);
if (desc_sorc == -1){
}
desc_targ = creat(argv[2], 0640);
if (desc_targ == -1){
exit(1);
}
while((lbajt = read(desc_sorc, buf, MAX)) > 0){
if (lbajt == -1) {
perror("position error");
exit(1);}
if (write(desc_targ, buf, lbajt) == -1)
{
exit(1);
}
}
if (lbajt == -1){
exit(1);
}
if (close(desc_sorc) == -1 || close(desc_targ) == -1){
exit(1);
}
exit(0);
}