String compression problem

i have tried making the logic of the problem but could not think of how can we print a character frequency single time. here is my code . please tell the changes i have to make to run my code .

Okay I corrected your code , please see https://ide.codingblocks.com/s/247797

ya i checked it and it is running as desired but i cannot understand this approach. like use of j, then i=j,j=i and all.
can you please explain a little bit to me ?

I’m just iterating until the same character occurs, and once I have iterated for characters that are same as s[i] , I don’t need to do them again. Also your code was printing the total frequency ,which was incorrect.
Dry run the code, its just basic implementation, there is nothing more to it.