finding the length of a char*

J

Jakob Bieling

Al-Burak said:
How can I find the length of a character pointer in 'C'?


If you mean the number of chars in the array the pointer points to,
then the general answer is: you can't. If this pointer points to an
array, where the end of the array is signalled by a 0-char, then you can
use strlen.

hth
 
R

roberts.noah

Neelesh said:
By posting to comp.lang.c

To the OP:

You could have avoided such replies by leaving out the word 'C' in your
question or by replacing it with 'C++'. Since you specified a language
that this group is not about you get smart-ass answers like the above.
However, without having specified the language as something other than
C++ your question would have been totally on-topic.
 
M

major

Al-Burak said:
Thanks folks!
The function I was looking for is strlen().

be careful with strlen, because it counts until a '\0'... the array
could be more longer ;-)
 
B

Ben Radford

Al-Burak said:
How can I find the length of a character pointer in 'C'?

TIA

If you mean the length (size would be a more appropriate term) of a
character pointer then just use 'sizeof(char*)'. For the length of a
string pointed to by the character pointer use 'strlen'.
 

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,434
Messages
2,571,691
Members
48,796
Latest member
Greg L.

Latest Threads

Top