Alx09

Ex1

Apr 21st, 2020
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 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 (!feof(f)) {
  12. fscanf(f, "%c", &b);
  13. if (a == b) cnt++;
  14. else{
  15. fprintf(g, "%c%u", a, cnt);
  16. a = b;
  17. cnt = 1;
  18. }
  19. }
  20. fclose(f);
  21. fclose(g);
  22. return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment