When first encounted, i has an indeterminate value on line 26. It is not initialized and using it like you do probably results in you accessing memory that is outside the bounds of the count array. Furthermore you set i to ch inside the loop, knowing that ch may be a value that is outside the bounds of the count array, causing more undefined behavior.