I'm at the very beginning of learning to code (specifically C). While writing a function which is counting the chars of an array for studying purposes, I was questioning myself (and I'm pretty sure about it), if there is the possibility to simplify this iteration:
int stringlength(char* s)
{
int i = 0;
while (s != NULL && *(s + i) != '\0')
i++;
return i;
}
I would like to keep the i++
within the iteration itself (for loop?).
I'm appreciating any hint you guys got for me. If you find something question unrelated which I'm doing wrong - please let me know.