循环,每次从第一个字符串中取出长度与第二个字符串相等的字符串(N个),进行比较,若不等则再从第二个字
为了解决用户可能碰到关于"求C语言中怎么用strstr函数求?求C语言中怎么用strstr"相关的问题,酷网经过收集整理为用户提供相关的解决办法,请注意,解决办法仅供参考,不代表本网同意其意见,如有任何问题请与本网联系。"求C语言中怎么用strstr函数求?求C语言中怎么用strstr"相关的详细问题如下:求C语言中怎么用strstr函数求!位置!
没有这样的函数 不过你可以自己写不过意义不大 因为你没办法确定向前查找到哪里结束 除非你把原
扩展阅读,根据您访问的内容系统为您准备了以下扩展内容,希望对您有帮助。
C语言中,strstr函数的功能是什么?不用库函数,自己写怎么写?
C语言中,strstr函数的功能是寻找字符串中子串出现的位置,自己写的步骤如下。
需要准备的材料分别有:电脑、C语言编译器。
1、首先,打开C语言编译器,新建一个初始.cpp文件,例如:test.cpp。
2、在test.cpp文件中,输入C语言代码:。
int fun(char *a, char *b)
{
int i, j, alen = strlen(a), blen = strlen(b);
for (i = 0; i < alen - blen + 1; i++)
if (a[i] == b[0]) {
for (j = 1; j < blen; j++) if (a[i + j] != b[j])break;
if (j == blen)
return i;
}
return -1;
}
3、编译器运行test.cpp文件,此时成功实现了strstr实现了字符串查找。
用汇编语言怎么实现C语言中strstr函数的功能
$ man strstr
SYNOPSIS
#include
char *strstr(const char *haystack, const char *needle);
DESCRIPTION
The strstr() function finds the first occurrence of the substring needle in the string haystack. The terminating '\0' characters are not compared.本回答被网友采纳
C语言 寻找字符串!要求:用strstr函数。
//---------------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
int main(void)
{
char s1[80],s2[70];
scanf("%s",s1); /*输入第一个字符串,以回车结束*/
fflush(stdin);
scanf("%s",s2); /*输入第二个字符串,以回车结束*/
printf("%d",strstr(s1,s2)-s1+1); /*输出结果*/
return 0;
}
//---------------------------------------------------------------------------