Josif_tepe

Untitled

Jun 5th, 2026
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6.  
  7. int main(int argc, char * argv[]) {
  8.     if(argc < 4) {
  9.         printf("Nema dovolno argumenti\n");
  10.         return 0;
  11.     }
  12.  
  13.     FILE * in = fopen(argv[1], "r");
  14.     FILE * out_parni = fopen(argv[2], "w");
  15.     FILE * out_neparni = fopen(argv[3], "w");
  16.  
  17.     if(in == NULL || out_neparni == NULL || out_parni == NULL) {
  18.         printf("Ne postecki fajlovi\n");
  19.         return 0;
  20.     }
  21.  
  22.     int i = 0;
  23.     char niza[2000], c;
  24.  
  25.     while((c = fgetc(in)) != EOF) {
  26.         if(isalpha(c)) {
  27.             niza[i] = c;
  28.             i++;
  29.         }
  30.         else {
  31.             if(i % 2 == 0) {
  32.                 for(int j = 0; j < i; j++) {
  33.                     fprintf(out_parni, "%c", niza[j]);
  34.                 }
  35.                 fprintf(out_parni, " ");
  36.             }
  37.             else {
  38.                 for(int j = 0; j < i; j++) {
  39.                     fprintf(out_neparni, "%c", niza[j]);
  40.                 }
  41.                 fprintf(out_neparni, " ");
  42.             }
  43.             i = 0;
  44.             niza[0] = '\0';
  45.         }
  46.         if(c == '\n') {
  47.             fprintf(out_neparni, "\n");
  48.             fprintf(out_parni, "\n");
  49.            
  50.         }
  51.  
  52.     }
  53.  
  54.     return 0;
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment