strstr, wcsstr (Windows CE 5.0)

Send Feedback

Developing an Application > Microsoft C Run-time Library for Windows CE > Run-time Library Reference

Find a substring.

char *strstr( const char *string, constchar *strCharSet);wchar_t *wcsstr( const wchar_t *string, constwchar_t *strCharSet);

Parameters

  • string
    Null-terminated string to search.
  • strCharSet
    Null-terminated string to search for.

Return Values

Each of these functions returns a pointer to the first occurrence of strCharSet in string, or NULL if strCharSet does not appear in string. If strCharSet points to a string of zero length, the function returns string.

Remarks

These functions are supported by all versions of the C run-time libraries.

The strstr function returns a pointer to the first occurrence of strCharSet in string. The search does not include terminating null characters. wcsstr is the wide-character version of strstr. The arguments and return value of wcsstr are wide-character strings. These two functions behave identically otherwise.

The following table shows generic-text routine mappings for this function.

TCHAR.H Routine _UNICODE Defined
_tcsstr wcsstr

For more information about TCHAR.H routines, see Generic Text Mappings.

Example

Description

The following example finds a substring by locating the first member of a specified character set.

Code

#include <string.h>
#include <stdio.h>

char str[] =    "lazy";
char string[] = "The quick brown dog jumps over the lazy fox";
char fmt1[] =   "         1         2         3         4         5";
char fmt2[] =   "12345678901234567890123456789012345678901234567890";

void main( void )
{
   char *pdest;
   int  result;
   printf( "String to be searched:\n\t%s\n", string );
   printf( "\t%s\n\t%s\n\n", fmt1, fmt2 );
   pdest = strstr( string, str );
   result = pdest - string + 1;
   if( pdest != NULL )
      printf( "%s found at position %d\n\n", str, result );
   else
      printf( "%s not found\n", str );
}
// Output
String to be searched:
   The quick brown dog jumps over the lazy fox
            1         2         3         4         5
   12345678901234567890123456789012345678901234567890

lazy found at position 36

Requirements

OS Versions: Windows CE 2.0 and later.

Header: stdio.h, string.h.

Link Library: coredll.dll.

See Also

strcmp

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.