谁能告诉我strstr 是干什么用的
请举例子!!3Q
char *strstr( const char *string, const char *strCharSet );
The strstr function returns a pointer to the first occurrence of strCharSet in string. The search does not include terminating null characters.
strstr函数返回一个指针,该指针指向string串中第一次出现strCharSet的地方.搜索不包括终止的null字符!
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 );
}