• Source
    1. #include <stdio.h>
    2.  
    3.  
    4.  
    5. void *Rle(char *str)
    6. {
    7. int len(char*item){int t=0;while(item[t] !='\0')t++;return t;}
    8. int si = len(str);
    9. int st=0,c_out=0,c_in=0,p=0;
    10. char *temp = malloc(len(str)+1);
    11.  
    12.  
    13.  
    14.  
    15. for(c_out=0;c_out<si;c_out++)
    16. {
    17.  
    18. for(c_in=c_out;c_in<si;c_in++)
    19. {
    20.  
    21. if(str[c_out]==str[c_in])
    22. {
    23. st++;
    24. c_out=c_in;
    25.  
    26. if(c_out == si-1)
    27. {
    28.  
    29.  
    30. *(temp+p)=str[c_out];
    31. p++;
    32. *(temp+p)=st+'0';
    33. p++;
    34. *(temp+p)='\0';
    35.  
    36. }
    37. }
    38.  
    39.  
    40. else
    41. {
    42. temp[p]=str[c_out];
    43. p++;
    44. *(temp+p)=st+'0';
    45. p++;
    46. st=0;
    47. c_out=c_in-1;
    48. break;
    49. }
    50. }
    51.  
    52.  
    53. }
    54.  
    55. return temp;
    56. }
    57.  
    58.  
    59.  
    60. int main()
    61. {
    62. printf("%s \n",Rle("x"));
    63. printf("%s \n",Rle("www"));
    64. printf("%s \n",Rle("wwwwwwiee"));
    65. printf("%s \n",Rle("youaregoddd"));
    66.  
    67. return 0;
    68.  
    69. }
    70.