Alx09

Untitled

Apr 21st, 2020
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main() {
  5. char a, b;
  6. unsigned cnt = 1;
  7. FILE *f, *g;
  8. f = fopen("in.txt", "r");
  9. g = fopen("out.txt", "w");
  10. fscanf(f, "%c", &a);
  11. while (fscanf(f, "%c", &b)) {
  12. if (a == b) cnt++;
  13. else{
  14. fprintf(g, "%c%u", a, cnt);
  15. a = b;
  16. cnt = 1;
  17. }
  18. if (b == '\n')
  19. break;
  20. }
  21. fclose(f);
  22. fclose(g);
  23. return 0;
  24. }
Add Comment
Please, Sign In to add comment