It's better to pass length as function argument instead of such loop. 
strlen works only with C-string with terminating null-character.