#include <stdio.h>
int strlength(char s[])
{
int i;
while (s[i] != '\0')
++i;
return i;
}
int main()
{
int x = strlength("abcd");
printf("%d", x);
return 0;
}
Im new to StackOver and possibly didn't understand the code formatting (and rules to post questions) correctly. This is a small program from K&R Chapter 2. A little bit modified which doesn't interfere with my problem. Apparently i is initialized before entering while cycle. It works fine I just don't get why? I used onlinegdb online compiler. Maybe is the compiler's "fault" but I don't think this book was written to take into account users compiler. Here is the original form:
int strlen(char s[])
{
int i;
while(s[i] != '\0')
++i;
return i;
}