strstr, _fstrstr

Description

Find a substring.

#include <string.h> Required only for function declarations  

char *strstr( const char *string1, const char *string2 );

char __far * __far _fstrstr( const char __far *string1,
const char __far *string2 );

string1 Searched string  
string2 String to search for  

Remarks

The strstr function returns a pointer to the first occurrence of string2 in string1.

The _fstrstr function is a model-independent (large-model) form of the strstr function. The behavior and return value of _fstrstr are identical to those of the model-dependent function strstr, with the exception that the arguments and return value are far pointers.

Return Value

These functions return either a pointer to the first occurrence of string2 in string1, or NULL if they do not find the string.

Compatibility

strstr

Standards:ANSI

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

_fstrstr

Standards:None

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:None

See Also

strcspn, strncat, strncmp, strncpy, _strnicmp, strpbrk, strrchr, strspn

Example

/* STRSTR.C */

#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