Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- char **merge(FILE *file1, FILE *file2);
- char **block;
- int main(int argc, char const *argv[]){
- int max_lines = 100;
- int buffer_length = 100;
- char buffer[buffer_length];
- char **block = (char **)calloc(max_lines, sizeof(char *));
- for(int i = 0; i < max_lines; i++){
- block[i] = (char *)calloc(buffer_length, sizeof(char *));
- }
- FILE *file1;
- FILE *file2;
- FILE *file3;
- FILE *file4;
- if(argc >= 5){
- file1 = fopen(argv[1], "r");
- file2 = fopen(argv[2], "r");
- file3 = fopen(argv[3], "r");
- file4 = fopen(argv[4], "r");
- }
- int *blocks = (int *)calloc(3, sizeof(int*));
- blocks[0] = merge(file1, file2);
- blocks[1] = merge(file3, file4);
- return 0;
- }
- char **merge(FILE *file1, FILE *file2){
- int max_lines = 100;
- int buffer_length = 100;
- char buffer[buffer_length];
- char **block = (char **)calloc(max_lines, sizeof(char *));
- for(int i = 0; i < max_lines; i++){
- block[i] = (char *)calloc(buffer_length, sizeof(char *));
- }
- int index = 0;
- while(fgets(buffer, buffer_length, file1)){
- strcpy(block[index], buffer);
- index += 2;
- }
- index = 1;
- while(fgets(buffer, buffer_length, file2)){
- strcpy(block[index], buffer);
- index += 2;
- }
- for(int i = 0; i < index; i++){
- printf(block[i]);
- }
- return block;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement