Josif_tepe

Untitled

Aug 24th, 2026
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.36 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <math.h>
  5. int main(int argc, char * argv[]) {
  6.  
  7.     if(argc < 4) {
  8.         printf("Ne vnesovte dovolno parametri\n");
  9.         return 0;
  10.     }
  11.     FILE * in1 = fopen(argv[1], "r");
  12.     FILE * in2 = fopen(argv[2], "r");
  13.     FILE * out = fopen(argv[3], "w");
  14.  
  15.     if(in1 == NULL || in2 == NULL) {
  16.         printf("Ne postoi datotekata\n");
  17.         return 0;
  18.     }
  19.  
  20.     char d1[2000], d2[2000];
  21.  
  22.     while(fgets(d1, 150, in1) != NULL && fgets(d2, 150, in2) != NULL) {
  23.         int broj_na_zborovi_d1 = 0, broj_na_zborovi_d2 = 0;
  24.        
  25.         for(int i = 0; i < strlen(d1); i++) {
  26.             if(d1[i] == ' ') {
  27.                 broj_na_zborovi_d1++;
  28.             }
  29.         }
  30.  
  31.         for(int i = 0; i < strlen(d2); i++) {
  32.             if(d2[i] == ' ') {
  33.                 broj_na_zborovi_d2++;
  34.             }
  35.         }
  36.  
  37.         if(broj_na_zborovi_d1 == broj_na_zborovi_d2) {
  38.             d1[strlen(d1) - 1] = '\0';
  39.             d2[strlen(d2) - 1] = '\0';
  40.            
  41.             fprintf(out, "%s %s\n", d1, d2);
  42.         }
  43.         else if(broj_na_zborovi_d1 > broj_na_zborovi_d2) {
  44.             d1[strlen(d1) - 1] = '\0';
  45.  
  46.             fprintf(out, "%s\n", d1);
  47.         }
  48.         else {
  49.          d2[strlen(d2) - 1] = '\0';
  50.             fprintf(out, "%s\n", d2);
  51.         }
  52.  
  53.     }
  54.  
  55. }
  56.  
  57.  
  58.  
  59.  
Advertisement
Add Comment
Please, Sign In to add comment