Advertisement
Josif_tepe

Untitled

Jan 18th, 2024
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 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.     char s[2000];
  23.     while(fgets(s, 1000, in) != NULL) {
  24.        
  25.         char zbor[2000];
  26.         int j = 0;
  27.         int brojac = 0;
  28.        
  29.         for(int i = 0; i < strlen(s); i++) {
  30.             if(isspace(s[i]) && s[i] != '\n') {
  31.                 if(brojac == 0) {
  32.                     for(int k = 0; k < j; k++) {
  33.                         printf("%c", zbor[k]);
  34.                     }
  35.                 }
  36.                 else {
  37.                     printf("#");
  38.                     for(int k = 0; k < j; k++) {
  39.                         printf("%c", zbor[k]);
  40.                     }
  41.                 }
  42.                 j = 0;
  43.                 brojac++;
  44.             }
  45.             else if(s[i] == '\n') {
  46.  
  47.                 for(int k = 0; k < j; k++) {
  48.                         printf("%c", zbor[k]);
  49.                     }
  50.                 printf("\n");
  51.             }
  52.             else {
  53.                 zbor[j] = s[i];
  54.                 j++;
  55.             }
  56.         }
  57.        
  58.     }
  59.     return 0;
  60. }
  61.  
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement