Re: Two Questions about "strlen", "strcat" and "strcpy"

From: Karthiik Kumar (kaykaydreamz_nospam_at_yahoo.com)
Date: 08/30/04


Date: 30 Aug 2004 05:03:08 GMT

Matt wrote:

> I have 2 questions:
>
> 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned
> value more approprate than a signed value? Why is unsighned value less
> appropriate?
>
>
>

    I cannot think of a string that has its length to be -ve. How would
a string of length -1 look like (as if that makes sense !! ) ?

> 2. Would there be any advantage in having strcat and strcpy return a
> pointer to the "end" of the destination string rather than returning a
> pointer to its beginning?

     With the whole lot of string manipulation functions expecting a
pointer to the beginning of the string , to have strcpy / strcat return
pointer to the beginning of the string would be orthogonal to the API,
instead of other ways like pointing to its 'end' etc.

-- 
   Karthik
-- 
comp.lang.c.moderated - moderation address: clcm@plethora.net


Relevant Pages

  • Re: "Mastering C Pointers"....
    ... A pointer is a kind of variable that can "point to" some object. ... has a type (pointer to int), and a value of some kind. ... You may know that you can access these integers by using array notation ... The function will take one argument, a string, and will return the length ...
    (comp.lang.c)
  • Re: pesky Pointers !!
    ... > and the function takes it as a reference instead of a copy. ... function may access the string passed directly, ... > *px dereferences the pointer to get the value ... If pTest is a pointer-to-string, *pTest is the string it points to ...
    (alt.comp.lang.learn.c-cpp)
  • Re: strtok ( ) help
    ... > splitCommandssomehow modifying the pointer, but I HAVE to call that ... Here's an idea of how to use the strtok() function. ... don't mind trashing the contents of a string s, ... will give you a loop that extracts the tokens one at a time from s. ...
    (comp.lang.c)
  • Re: new IL: C (sort of...).
    ... C doesn't need a string type... ... variant of PL/1 which was very Pascal-ish. ... - C does implement an array declaration. ... effectively converted into a pointer that can be used with the offset ...
    (comp.lang.misc)
  • Re: copy a string into a 2d array of chars
    ... This split function should allocate a 2D array of chars ... >focus the program the string is not actually split. ... later) is an array of char containing the original contents of the ... The i-th pointer will contain the starting address of the ...
    (comp.lang.c)