Using char-counting loop