Archived

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

JIMbond21

String length

Recommended Posts

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