Advertisement
FiddleComputers

File reading and concatenating

Dec 6th, 2020
891
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.26 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int concat(char* input_path1, char* input_path2, char* output_path)
  5. {
  6.     FILE *input_file1;
  7.     FILE *input_file2;
  8.     FILE *output_file;
  9.     int c;
  10.  
  11.     output_file = fopen(output_path, "w");
  12.     input_file1 = fopen(input_path1, "r+");
  13.  
  14.     while((c = fgetc(input_file1)) != EOF)
  15.     {
  16.         printf("%c", (char)c);
  17.         fprintf(output_file, "%c", (char)c);
  18.     }
  19.  
  20.     fclose(input_file1);
  21.     input_file2 = fopen(input_path2, "r+");
  22.  
  23.     while((c = fgetc(input_file2)) != EOF)
  24.     {
  25.         printf("%c", (char)c);
  26.         fprintf(output_file, "%c", (char)c);
  27.     }
  28.  
  29.     fclose(input_file2);
  30.     fclose(output_file);
  31. }
  32.  
  33. char* lirechar()
  34. {
  35.     int n=0;
  36.     char *c=(char*)malloc(1);
  37.     char saisie=getchar();
  38.     while(saisie!='\n')
  39.     {
  40.         c[n]=saisie;
  41.         saisie=getchar();
  42.         n++;
  43.         c=(char*)realloc(c,n+1);
  44.     }
  45.     c[n]='\0';
  46.     return c;
  47.  
  48. }
  49.  
  50.  
  51. int main()
  52. {
  53.     char* input_path1;//={'1','.','t','x','t'};
  54.     char* input_path2;//={'2','.','t','x','t'};
  55.     char* output_path;//={'3','.','t','x','t'};
  56.  
  57.     input_path1=lirechar();
  58.     input_path2=lirechar();
  59.     output_path=lirechar();
  60.  
  61.     concat(input_path1, input_path2, output_path);
  62.  
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement