Hello
I am trying to open 2 inputfiles and create 1 outputfile.
This outputfile will be a concatenation of the 2 inputfiles.
I want to copy the first file to the outputfile but when i try to read the outputfile I get an error : U dont have permission to open the document ......
Is there someone who knows the problem?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#define BUFSIZE 512
char buff[BUFSIZE];
int main (int argc, char *argv[]){
int file1, file2, output;
int bytes;
if (argc != 4){
perror("ERROR");
exit(0);
}
if ((file1 = open(argv[1], O_RDONLY)) < 0){
perror("ERROR");
exit(0);
}
if ((file2 = open(argv[2], O_RDONLY)) < 0){
perror("ERROR");
exit(0);
}
if ((output = open(argv[3], O_CREAT | O_WRONLY| S_IWRITE)) < 0){
perror("ERROR");
exit(0);
}
while ((bytes = read(file1, buff, BUFSIZE)) > 0)
write(output, buff, BUFSIZE);
return 0;
}