Advertisement
Josif_tepe

Untitled

Jan 18th, 2024
648
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 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]) && s[i] != '\n') {
  29.                 spaces++;
  30.             }
  31.         }
  32.        
  33.         if(spaces < 3) {
  34.             fprintf(out, "Red %d\n", red);
  35.             brojac++;
  36.         }
  37.         red++;
  38.     }    
  39.    fprintf(out, "Postojat %d takvi redovi\n", brojac);
  40.     return 0;
  41. }
  42.  
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement