3-10.c

来自「数据结构用C语言实现」· C语言 代码 · 共 25 行

C
25
字号
#include "stdio.h"
#include <string.h>
int  nfind ( char  *B,  char  *A )
{   
    int  i, j, start  = 0;
    int  lasts = strlen (B ) -1;
    int  lastp =  strlen ( A) -1 ;
    int  endmatch =  lastp;
    for(i=0; endmatch<=lasts;  endmatch++,  start++)  {
        if ( B[endmatch] == A[lastp ])
               for ( j=0, i=start;  j<lastp && B[i]==A[j]; i++,j++)
                ;
    if ( j == lastp )
       return start;    /*成功  */
    }
    return  -1;
}

void main ()
{
	char s[]="Sit please.";
	char t[]="please ";
	int po=nfind(s,t);
	printf("%d",po);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?