By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,382 Members | 1,567 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,382 IT Pros & Developers. It's quick & easy.

character pointer length

P: n/a
How do I get the length of a character pointer?

TIA

Dec 11 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Jamiil wrote:
How do I get the length of a character pointer?

TIA

sizeof(char *)
Dec 11 '05 #2

P: n/a
Jamiil a écrit :
How do I get the length of a character pointer?


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
Dec 11 '05 #3

P: n/a
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!

Dec 12 '05 #4

P: n/a
"Jamiil" <ja******@netscape.net> writes:
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!


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

/Niklas Norrthon
Dec 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.