#include <stdio.h>
#include <string.h>
#include <string.h>
int Find_Pos(char *s,char * t)
{
char * p;
p = strstr(s,t);
int result = -1;
if (p)
{
int sn = strlen(s);
int pn = strlen(p);
printf("源地址:%s\n",s);
printf("返地址:%s\n",p);
result = sn - pn;
printf("%d,%d\n",sn,pn);
}
return result;
}
main()
{
char *s="Golden Global View";
char *l="lob";
printf("%d\n",Find_Pos(s,l));
return 0;
}
本文展示了一个使用C语言strstr函数查找子字符串位置的例子。通过一个具体的程序代码,演示了如何确定子字符串在主字符串中的相对起始位置,并返回该位置。

被折叠的 条评论
为什么被折叠?



