fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. // #include <string.h>
  4.  
  5. char *func(char *s)
  6. {
  7. char *inp = s; // indata pointer
  8. char *rData = (char *)malloc(100 * sizeof(char)); // returning data area allocate
  9. char *r2 = rData; // returning data pointer
  10. while (*s) { // reach to indata end?
  11. while (*s == *inp) ++inp;
  12. *r2++ = '0' + inp - s; // count set
  13. *r2++ = *s; // char set
  14. s = inp; // indata pointer shift
  15. }
  16. return rData;
  17. }
  18.  
  19. int main()
  20. {
  21. char s[] = "1"; // initial indata
  22. char *p = s;
  23. int i;
  24. printf("%s\n", p);
  25. for (i = 0; i < 10; ++i) {
  26. p = func(p);
  27. printf("%s\n", p);
  28. }
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 2380KB
stdin
Standard input is empty
stdout
1
11
21
1211
111221
312211
13112221
1113213211
31131211131221
13211311123113112211
11131221133112132113212221