Bug: you assume that the result will never be longer than the original string while in fact it could be twice as long. For example
abcdwould yielda1b1c1d1.Instead of using
memsetto initializeresultyou can also initialize it to 0 like this:char result[len] = { 0 };You don't have to assign the counter on every iteration to the result. Simply increment the counter while the letter doesn't change and then add the count afterwards.
Another bug: the way you convert the counter into a string will stop working for any number larger than 9. You want
sprintf.Also
strlenreturns the length of the string excluding the terminatingNULLcharacter so yourresultis short by 1 in any case.Given the fairly severe bugs you really ought to test your code better.