character pointer length

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jamiil

    #1

    character pointer length

    How do I get the length of a character pointer?

    TIA

  • Robert Harris

    #2
    Re: character pointer length

    Jamiil wrote:[color=blue]
    > How do I get the length of a character pointer?
    >
    > TIA
    >[/color]
    sizeof(char *)

    Comment

    • Emmanuel Delahaye

      #3
      Re: character pointer length

      Jamiil a écrit :[color=blue]
      > How do I get the length of a character pointer?[/color]

      Do you meant size ? The sizeof operator returns the size of any object.
      Time to reopen your C-book ?

      Length is more likely related to a string. If you mean so, strlen() is
      your friend.

      Note that a 'character pointer' is vague. On one hand, you have a
      pointer to char:

      char *p;

      and on the other hand you have a string:

      "hello"

      that is an array of char terminated by a 0. The chars contain the values
      of the characters:

      {'h','e','l','l ','o',0}

      --
      A+

      Emmanuel Delahaye

      Comment

      • Jamiil

        #4
        Re: character pointer length

        Yes! strlen() is what I was looking for.
        As a mostly C++ programmer, it has been eons since the last time I used
        char or char* in any program, but in the project, which is ~35k lines
        of code, 3 ones are dedicated to a 'const char*' value, thus I needed
        to refresh my memory on the stdlib.h and/or stdio stuff.
        Thanks Emanuel, strlen() is what I need to use in this case.
        Keep up the good work!

        Comment

        • Niklas Norrthon

          #5
          Re: character pointer length

          "Jamiil" <jalqadir@netsc ape.net> writes:
          [color=blue]
          > Yes! strlen() is what I was looking for.
          > As a mostly C++ programmer, it has been eons since the last time I used
          > char or char* in any program, but in the project, which is ~35k lines
          > of code, 3 ones are dedicated to a 'const char*' value, thus I needed
          > to refresh my memory on the stdlib.h and/or stdio stuff.
          > Thanks Emanuel, strlen() is what I need to use in this case.
          > Keep up the good work![/color]

          Btw, the declaration of strlen resides in <string.h>, (which is equvalent
          to <cstring> in C++).

          /Niklas Norrthon

          Comment

          Working...