Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/syscall.h>
- #define MAXN 10001
- int main()
- { //var para guardar o caminho dos arquivos
- char file1[MAXN], file2[MAXN];
- printf("Caminho do primeiro arquivo:"); //Lê o caminho
- scanf(" %s", file1);
- printf("Caminho do segundo arquivo:");
- scanf(" %s", file2);
- int id_file1 = open(file1, O_RDONLY); //System call pra abrir o arquivo.
- int id_file2 = open(file2, O_RDONLY); //Open retorna o id do arquivo aberto.
- int bytes1, bytes2;
- //printf("%d %d\n", id_file1, id_file2); //Imprime os id's
- if( (bytes1 = read(id_file1, file1, MAXN) ) < 0 || ( bytes2 = read(id_file2, file2, MAXN)) < 0) //Lê o conteúdo do arquivo e
- { //Se read retorna 0, houve algum erro
- puts("ERROR");
- exit(0);
- }
- int id_ans = open("Conc.txt", O_CREAT | O_TRUNC | O_APPEND | O_WRONLY, S_IRUSR); //Cria arquivo
- if( write( id_ans, file1, bytes1 ) < 0 || write(id_ans, file2, bytes2 ) < 0 ) //Escreve no arquivo criado
- {
- puts("ERROR1");
- exit(0);
- }
- close(id_file1); //Fecha arquivo
- close(id_file2);
- close(id_ans);
- puts("DONE");
- }
Advertisement
Add Comment
Please, Sign In to add comment