Advertisement
Extremum

Untitled

Jun 8th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char *argv[]){
  5.     char str1[50], str2[50];
  6.     FILE *input1, *input2, *output;
  7.     if (argc != 4){
  8.         printf("Enter 3 file names.\n");
  9.         return 0;
  10.     }
  11.     input1 = fopen(argv[1], "r");
  12.     input2 = fopen(argv[2], "r");
  13.     output = fopen(argv[3], "w");
  14.     if (input1 == NULL || input2 == NULL){
  15.         printf("Error!\n");
  16.         return 0;
  17.     }
  18.     while(!feof(input1) || !feof(input2)){
  19.         if (fgets(str1, 50, input1))
  20.             fprintf(output, "%s", str1);
  21.         if (fgets(str2, 50, input2))
  22.             fprintf(output, "%s", str2);
  23.     }
  24.     printf("Success!\n");
  25.     fclose(input1);
  26.     fclose(input2);
  27.     fclose(output);
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement