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

Re: strcat strncat and strlen

Subject: Re: strcat strncat and strlen
From: "Bartc"
Date: Mon, 31 Mar 2008 10:05:18 GMT
Newsgroups: comp.lang.c


"santosh" <santosh.k83@xxxxxxxxx> wrote in message 
news:fspevv$2e1$1@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Bill Cunningham wrote:
>
>>> 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.
>
> It is a part of a C string. However it is not counted by strlen.
>
>> 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 format for size_t is %zu. If your compiler does not support this
> then the next best method is to use %lu and cast it's argument to
> unsigned long.

Printing the value of hello instead of t has a bigger effect than using the 
wrong format spec.

-- 
Bart 



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