Jump to content
  • Advertisement

Archived

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

Zeke

Finding a string in an array or chars

This topic is 6292 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

I have been using strcspn() to find the string "AUDIO" in char TextBuffer[]. Everything was going fine until i had an occurance of HORATIO where I annoyingly found that strcspn() doesnt find the string but just the first letter in that string it comes across. I cannot find in the msdn how to find a string withing an array (of course it must be in msdn but after looking for hours i cannot find it). SO can anyone point me in the right direction? Thanks for your time

Share this post


Link to post
Share on other sites
Advertisement
I think the function you are looking for is strstr().

It returns a pointer to the first occurance of the string
you are searching for.

TCHAR *szString = "BIG AUDIO DYNAMITE";
TCHAR *pSub = strstr(szString, "AUDIO");
if(pSub != (TCHAR*) NULL)
{
// Found it..
}
else
{
// Didn''t find it..
}

HTH,
// CHRIS

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!