char * strstr(const char *s1, const char *s2)该函数返回s1字符串中s2字符串出现的首位置。如果s1中没有找到s2,则返回空指针。
示例
//Visual Studio中加上这句才可以使用scanf()
//否则只能使用scanf_s()
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
//argc: 参数个数 argv[]: 参数数组
int main(int argc, char *argv[])
{
const char * s1 = "this is a string1 and string2!";
const char * s2 = "string";
//该函数返回s1字符串中s2字符串首次次出现的位置,
//如果未找到s1字符中,则返回空指针
char * c = strstr(s1, s2);
if (c != NULL)
puts(c);
system("pause");
return 0;
}
运行测试