The strlen function is expensive. For every call it must loop over every character until a nul terminator is found. Therefore, it is very unwise to call it more often than needed. This is bad code:
...