Move the strlen outside the loop