Advertisement
Josif_tepe

Untitled

Jan 18th, 2024
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 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.      char s[2000];
  19.      while(fgets(s, 1000, in) != NULL) {
  20.          for(int i = 0; i < strlen(s); i++) {
  21.              if(isdigit(s[i])) {
  22.                  int x = (s[i] - '0');
  23.                  int j = i + 1;
  24.                  while(j < strlen(s) && x > 0) {
  25.                      fprintf(out, "%c", s[j]);
  26.                      x--;
  27.                      j++;
  28.                  }
  29.                  i = j - 1;
  30.              }
  31.          }
  32.      }
  33.    
  34.     return 0;
  35. }
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement