Advertisement
Josif_tepe

Untitled

Jan 18th, 2024
558
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4.  
  5. int main(int argc, const char * argv[]) {
  6.  
  7.     if(argc < 3) {
  8.         printf("Vlezna  datoteka i izlezna treba da se vnesat kako argument\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("Fajlot ne postoi\n");
  16.         return 0;
  17.     }
  18.     if(out == NULL) {
  19.         printf("Fajlot ne postoin\n");
  20.         return 0;
  21.     }
  22.  
  23.     char s[2000];
  24.     int red = 1, brojac = 0;;
  25.     while(fgets(s, 1000, in) != NULL) {
  26.         int spaces = 1;
  27.         for(int i = 0; i < strlen(s); i++) {
  28.             if(isspace(s[i])) {
  29.                 spaces++;
  30.             }
  31.         }
  32.         if(spaces > 4) {
  33.             fprintf(out, "Red %d\n", red);
  34.             brojac++;
  35.         }
  36.         red++;
  37.     }    
  38.    fprintf(out, "Postojat %d takvi redovi\n", brojac);
  39.     return 0;
  40. }
  41.  
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement