Advertisement
Josif_tepe

Untitled

Jan 20th, 2024
687
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. int main(int argc, const char * argv[]) {
  7.     if(argc < 3) {
  8.         printf("Vlezna i izlezna se vnesuvaat kako argumenti\n");
  9.         return 0;
  10.     }    
  11.     FILE *in = fopen(argv[1], "r");
  12.     FILE *out = fopen(argv[2], "w");
  13.  
  14.     if(in == NULL) {
  15.         printf("Ne validna vlezna datoteka\n");
  16.         return 0;
  17.     }
  18.     if(out == NULL) {
  19.         printf("Ne validna izlezna datoteka\n");
  20.     }
  21.     char ime[1000];
  22.     int a, b, c, d;
  23.     int brojac = 0;
  24.     while(fscanf(in, "%s%d%d%d%d", ime, &a, &b, &c, &d) != EOF) {
  25.         float prosek = (float) (a + b + c + d) / 4.0;
  26.         if(prosek > 5) {
  27.             fprintf(out, "%s %f\n", ime, prosek);
  28.             brojac++;
  29.         }
  30.     }
  31.     fprintf(out, "%d\n", brojac);
  32.     return 0;
  33. }
  34.  
  35.  
  36. /*
  37. 7
  38. 7 2 -1 0 -30 2 -15
  39. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement