Jump to content
  • Advertisement

Archived

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

JIMbond21

String length

This topic is 5527 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!