Archived

This topic is now archived and is closed to further replies.

JIMbond21

String length

Recommended Posts

JIMbond21    122
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

Share this post


Link to post
Share on other sites
Monder    993
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

Share this post


Link to post
Share on other sites
Sneftel    1788
strlen

EDIT: oh nos!! ownz0red by teh monz0r!

[edited by - sneftel on August 8, 2003 4:01:55 PM]

Share this post


Link to post
Share on other sites
rypyr    252
I guess it''s too hard these days to look these things up in books or type "length of a string" in google

Share this post


Link to post
Share on other sites
Typhoon    122
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;
}

Share this post


Link to post
Share on other sites
Monder    993
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]

Share this post


Link to post
Share on other sites