String length
How do I determine the length of a string once I have passed it into a funtion using a pointer to the string, example:
void somefuntion( char* String )
{
//Now I need the length of the sring, how do I get it
}
Any help is apprecieated.
THX,
JAP
Just use strlen like this
int Length = strlen(String);
you''ll need to include the correct header and I''m not completely sure but it''s either stdio.h or stdlib.h
int Length = strlen(String);
you''ll need to include the correct header and I''m not completely sure but it''s either stdio.h or stdlib.h
strlen
EDIT: oh nos!! ownz0red by teh monz0r!
[edited by - sneftel on August 8, 2003 4:01:55 PM]
EDIT: oh nos!! ownz0red by teh monz0r!
[edited by - sneftel on August 8, 2003 4:01:55 PM]
I guess it''s too hard these days to look these things up in books or type "length of a string" in google
quote:Original post by Monder
Just use strlen like this
int Length = strlen(String);
you''ll need to include the correct header and I''m not completely sure but it''s either stdio.h or stdlib.h
The header is string.h.
Or you make your own function like this.
int StrLen(char *s)
{
int i;
for(i = 0; *s; s++, i++)
;
return i;
}
quote:The header is string.h.
Well I did a couple of tests (I'm bored) and on MinGW it works with just stdio.h but on VC++ 6.0 you need stdio.h and string.h so i guess it depends on your compiler.
Oh and Sneftel
[edited by - Monder on August 8, 2003 4:59:25 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement