.length() equivalent for char array

Nov 21, 2008 at 12:49am
I have a char myArray[8] that I'm passing to a function. In my function I need to capture the length of the array similar to how length() returns the number of chars in a string. Is there a function out there that will do the job?

Thanks,
Return 0;
Nov 21, 2008 at 1:16am
Do you need to know the size of the array (how many characters you can write without producing a segmentation fault) or the size of the string?
For the latter, you can use int strlen(char*) defined in string.h (cstring for C++).
For the former, you'll have to pass the known size. There's no way to determine the size of an array from its pointer (unless it's a static array, and only under certain conditions).
Nov 21, 2008 at 1:25am
int strlen(char*) was exactly what I was looking for. Thanks!

Topic archived. No new replies allowed.