Advertisement
matbiz01

Untitled

Mar 13th, 2021
870
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.49 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. char **merge(FILE *file1, FILE *file2);
  6. char **block;
  7.  
  8. int main(int argc, char const *argv[]){
  9.     int max_lines = 100;
  10.     int buffer_length = 100;
  11.     char buffer[buffer_length];
  12.  
  13.     char **block = (char **)calloc(max_lines, sizeof(char *));
  14.     for(int i = 0; i < max_lines; i++){
  15.         block[i] = (char *)calloc(buffer_length, sizeof(char *));
  16.     }
  17.  
  18.     FILE *file1;
  19.     FILE *file2;
  20.     FILE *file3;
  21.     FILE *file4;
  22.     if(argc >= 5){
  23.         file1 = fopen(argv[1], "r");
  24.         file2 = fopen(argv[2], "r");
  25.         file3 = fopen(argv[3], "r");
  26.         file4 = fopen(argv[4], "r");
  27.     }
  28.  
  29.     int *blocks = (int *)calloc(3, sizeof(int*));
  30.     blocks[0] = merge(file1, file2);
  31.     blocks[1] = merge(file3, file4);
  32.     return 0;
  33.  
  34. }
  35.  
  36. char **merge(FILE *file1, FILE *file2){
  37.     int max_lines = 100;
  38.     int buffer_length = 100;
  39.     char buffer[buffer_length];
  40.  
  41.     char **block = (char **)calloc(max_lines, sizeof(char *));
  42.     for(int i = 0; i < max_lines; i++){
  43.         block[i] = (char *)calloc(buffer_length, sizeof(char *));
  44.     }
  45.    
  46.     int index = 0;
  47.     while(fgets(buffer, buffer_length, file1)){
  48.         strcpy(block[index], buffer);
  49.         index += 2;
  50.     }
  51.  
  52.     index = 1;
  53.     while(fgets(buffer, buffer_length, file2)){
  54.         strcpy(block[index], buffer);
  55.         index += 2;
  56.     }
  57.    
  58.     for(int i = 0; i < index; i++){
  59.         printf(block[i]);
  60.     }
  61.     return block;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement