📄 字符串匹配查找的实现.txt
字号:
字符串匹配/查找的实现[原创]
该程序查找second字符串在first字符串中的位置,如果不存在,则返回-1。另外,这个程序还有很大的可优化余地,以后有时间慢慢补充。
#i nclude <conio.h>
int AtPos(char *p,char *q)/* to judge whether the second string exists int the first one*/
{
int i,j;
for(i=0;p[i];i++)
{
for(j=0;q[j]&&q[j]==p[i+j];j++)
;
if(!q[j])
return i;
}
return -1;
}
void main()
{
char first[80],second[80];
int pos;
clrscr();
printf("\nPlease input the first string....\n");
gets(first);
printf("\nPlease input the second string....\n");
gets(second);
pos=AtPos(first,second);
if(pos==-1)
printf("\nThe second string does not exist in the first one.\n");
else
printf("\nFOUND!The Position is %4d\n",pos);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -