转自某牛牛对我的一个问题的解释: “ #include #include
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 ”
不知道这一段代码对你有没有什么帮助 或许有,没怎么仔细看,,不过函数的功能是在里面的了 | |