Your problem is pretty simple. In a
for loop, after the end of each loop, the third parameter (
<increment command>) of the loop is executed, every time.
for (<initialization>; <condition>; <increment command>)
In your case your
<increment command> is
i gets incremented by 1 in each iteration. But, in your loop, after each iteration, you also increment
i yourself. So
i gets incremented by 2 in every loop instead of just 1. To solve that just remove the
i++s from inside the loop. The increment command will take care of it itself.
So your function should be:
int counter(char text)
int length = strlen(text), counter = 0;
for (int i = 0; i < length; i++)
You don't even need the
else clause ;).
If this answers your question please accept it by clicking the gray check-mark to the left, so that it becomes green. You can also vote it up by pressing the up arrow above the check-mark. And don't forget to keep coding!