instr.c

来自「Free Chat beta release 2 fot linux,采用C语言」· C语言 代码 · 共 61 行

C
61
字号
/*   instr.c      By Bill Kendrick   New Breed Software   kendrick@zippy.sonoma.edu   http://zippy.sonoma.edu/kendrick/   June 27, 1996 - June 27, 1996   Added #include <string.h> - Sept. 22, 1997*/#include <string.h>#include "instr.h"/* Returns the location within "string" that "word" begins, or -1. */int instr(char * string, char * word){  int i, far, started, found;    found = 0;  started = -1;  far = 0;    if ((strlen(word) != 0) && (strlen(word) <= strlen(string)))    {      for (i = 0; i < strlen(string); i++)	{	  if (string[i] == word[far])	    {	      	      if (started == -1)		started = i;	      	      far = far + 1;	      if (far == strlen(word))		{		  found = 1;		  far = 0;		}	    }	  else	    {	      if (found == 0)		{		  far = 0;		  started = -1;		}	    }	}    }    /* Make sure we found the WHOLE word, not just the beginning! */    if (found == 0)    started = -1;    return(started);}

⌨️ 快捷键说明

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