comp.lang.c
[Top] [All Lists]

Re: strcat strncat and strlen

Subject: Re: strcat strncat and strlen
From: "Bill Cunningham"
Date: Mon, 31 Mar 2008 00:59:23 GMT
Newsgroups: comp.lang.c

> You are not making any sense. Are you asking why strlen exists? It
> should be obvious, even to you. How else do you find the length of a
> zero terminated string?

    C must not count '\0' as being part of a string. This is the simple code 
I tried,

int main(void) {
        size_t t;
        char hello[]="hello world\n";
        t=strlen(hello);
        printf("%i",hello);
}
    The integer returned was 12. When I removed the '\n' from the string 
and recompiled 11 was the number returned.
    Why in production code would someone want to know the length of a 
string? That's what I am asking. Hence my inexperience speaks for itself.



<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy