Re: strcat strncat and strlen




"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


.



Relevant Pages

  • Re: When is an empty string not an empty string?
    ... In the inline case, an empty string is returned when the end of the input string is reached before any conversions have been performed. ... Now we've exhausted the format spec string. ...
    (comp.lang.tcl)
  • Re: strcat strncat and strlen
    ... Bartc wrote: ... C must not count '\0' as being part of a string. ... using the wrong format spec. ...
    (comp.lang.c)
  • Re: String cat algo
    ... Zero terminated string ... Any decent dynamic string library has reallocation "heuristics" to ... avoid too many realloc calls, ... > comparitive zero terminated string approach is a lot faster. ...
    (comp.lang.asm.x86)
  • Re: BC30518:Overload resolution failed because no accessible Join can be called with these arguments
    ... "Bart" schrieb: ... Dim hvd As String ... The first parameter of 'Join' must be either an array of string ') or an array of object '). ...
    (microsoft.public.dotnet.languages.vb)
  • Re: String cat algo
    ... The choice of the string type you use is a tradeoff betwen simplcity ... and speed versus safety and performance loss. ... Zero terminated string ... complicated ways but a comparitive zero terminated string approach is a ...
    (comp.lang.asm.x86)