Advertisement
Alx09

SDA 1.3

Feb 26th, 2024
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     FILE* f, *g;
  7.     char a, b;
  8.     int numar, i, count = 1;
  9.    
  10.     if (fopen_s(&f, "in.txt", "rt") != 0) {
  11.         printf("Fiser negasit");
  12.         return 0;
  13.     }
  14.     if (fopen_s(&g, "out.txt", "wt") != 0) {
  15.         printf("Fiser negasit");
  16.         return 0;
  17.     }
  18.     fscanf_s(f, "%c", &a);
  19.     while (fscanf_s(f, "%c", &b) != EOF) {
  20.         if (a == b) {
  21.             count++;
  22.         }
  23.         else {
  24.             fprintf_s(g, "%c%d", a, count);
  25.             count = 1;
  26.             a = b;
  27.         }
  28.     }
  29.     fclose(f);
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement