I'm having trouble finding the length of an pointer array. Let's say I have:
char array[40] = "hello"; // size 40
int length = sizeof array / sizeof array[0]; // no problem returns 40
//How do I get the length of the array with only a pointer to the first element in that array?
char* pchar = array;
//if
std::strlen(pchar); // this returns the length of 5... i want length 40
//if
int count = 0;
while(true)
{
if(*(pchar + count) == '\0') // returns 5...
break;
count++;
}
How do I get it to return length 40 just from a pointer to the first element in the array?
I found that I can do this.
int count = 0;
while(true)
{
if(*(pchar + count) == '\0' && *(pchar + count + 1) != '\0')
break;
count++;
}
This returns 39, this is good but I feel like this can be buggy in some situations.