character pointer length

E

Emmanuel Delahaye

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}
 
J

Jamiil

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!
 
N

Niklas Norrthon

Jamiil said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,172
Messages
2,570,933
Members
47,472
Latest member
blackwatermelon

Latest Threads

Top