To state it bluntly: this code is crap.
My advise:
- describe in a comment what the function aims to calculate (it seems to be some length encoding compression algorithm, but it's not clear how exaclty)
- make all blocks
{ ... }
- do not rely on the comma operator (use
;
- see 2. above) - modify the iterating variables only at one place and not at several places (
sc, i, len, res, len
) - do consistent initialisation (e.g. not clear why initially
count = 1
and later you do count = 0
etc.)
Try to describe the function, define some unit tests and finally properly re-implement it.
Cheers
Andi