Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Find the size of pointer in C

Name: Anonymous 2009-06-25 0:32

suppose char *str has some bytes(not malloced), how can i determine the size of *str without access to str itself?

Name: Anonymous 2009-06-25 3:27


int strlen(unsigned char *string_start)
{
   /* Initialize a unsigned char pointer here  */
   /* A loop that starts at string_start and
    * is increment by one until it's value is zero,
    *e.g. while(*s!=0) or just simply while(*s) */
   /* Return the difference of the incremented pointer and the original pointer */
}

Name: Anonymous 2009-06-25 4:30

>>19

int strlen(unsigned char *string_start)
{ return strrchr(string_start, 0) - string_start; }

Name: Anonymous 2009-06-25 4:35

>>20
actually, that should be:
size_t strlen(const char *string_start)
{ return (size_t)(strchr(string_start, 0) - string_start); }

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List