Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <unistd.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- int main()
- {
- char fname1[100], fname2[100], txt[1000];
- scanf("%s%s", fname1, fname2);
- int file;
- if(file = open(fname1, O_RDONLY) < 0){
- printf("arquivo não encontrado %s", fname1);
- return -1;
- }
- struct stat info;
- if(stat(fname1, &info)<0){
- printf("erro na leitura das informacoes de %s", fname1);
- return -1;
- }
- int tamfinal = info.st_size;
- if(read(file, txt, info.st_size)<0){
- printf("erro ao ler o arquivo %s", fname1);
- return -1;
- }
- close(file);
- if(file = open(fname2, O_RDONLY) < 0){
- printf("arquivo nao encontrado %s", fname2);
- return -1;
- }
- if(stat(fname2, &info)<0){
- printf("erro na leitura das informacoes de %s", fname2);
- return -1;
- }
- if(read(file, txt+tamfinal, info.st_size)<0){
- printf("erro ao ler o arquivo %s", fname2);
- return -1;
- }
- close(file);
- tamfinal += info.st_size;
- txt[tamfinal] = "\0";
- printf("%s\n%d", txt, tamfinal);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment