fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define LONG 80
  5. #define SHORT 20
  6. void longtext(char longtxt[LONG], char shorttxt[SHORT])
  7. {
  8. int i, j=0, count=0;
  9. char letter;
  10. for (i = 0; i <= strlen(longtxt); ++i)
  11. {
  12. if (i == 0)
  13. {
  14. letter = longtxt[i];
  15. ++count;
  16. }
  17. else if (letter == longtxt[i])
  18. ++count;
  19. else
  20. {
  21. shorttxt[j] = letter;
  22. snprintf(&shorttxt[j + 1],2,"%d",count);
  23. j += 2;
  24. count = 1;
  25. letter = longtxt[i];
  26. }
  27. }
  28. }
  29. int main()
  30. {
  31. char longtxt[LONG] = "aaabbdddd",shorttxt[SHORT];
  32. longtext(longtxt,shorttxt);
  33. printf("%s", shorttxt);
  34. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
a3b2d4