Jeremiah_

Untitled

Sep 5th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.22 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <fcntl.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <unistd.h>
  7. #include <sys/stat.h>
  8. #include <sys/types.h>
  9.  
  10. int main()
  11. {
  12.     char fname1[100], fname2[100], txt[1000];
  13.     scanf("%s%s", fname1, fname2);
  14.     int file;
  15.     if(file = open(fname1, O_RDONLY) < 0){
  16.         printf("arquivo não encontrado %s", fname1);
  17.         return -1;
  18.     }
  19.     struct stat info;
  20.     if(stat(fname1, &info)<0){
  21.         printf("erro na leitura das informacoes de %s", fname1);
  22.         return -1;
  23.     }
  24.     int tamfinal = info.st_size;
  25.     if(read(file, txt, info.st_size)<0){
  26.         printf("erro ao ler o arquivo %s", fname1);
  27.         return -1;
  28.     }
  29.     close(file);
  30.     if(file = open(fname2, O_RDONLY) < 0){
  31.         printf("arquivo nao encontrado %s", fname2);
  32.         return -1;
  33.     }
  34.     if(stat(fname2, &info)<0){
  35.         printf("erro na leitura das informacoes de %s", fname2);
  36.         return -1;
  37.     }
  38.     if(read(file, txt+tamfinal, info.st_size)<0){
  39.         printf("erro ao ler o arquivo %s", fname2);
  40.         return -1;
  41.     }
  42.     close(file);
  43.     tamfinal += info.st_size;
  44.     txt[tamfinal] = "\0";
  45.     printf("%s\n%d", txt, tamfinal);
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment