Archived

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

Zeke

Finding a string in an array or chars

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