发布网友 发布时间:2022-04-25 03:17
共1个回答
热心网友 时间:2023-10-22 21:26
//你把字符串和int搞混淆了,char "6"并不是int 6
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
#define MAXSTRLEN 256
#define MAXSTRSIZE 256
#define TRUE 1
#define FALSE 0
#define ERROR 0
#define OVERFLOW -2
typedef int Status;
typedef char SString[MAXSTRLEN+1];
SString s;
// 在主串S的第POS个字符之后,寻找模式T的匹配位置
int Index( SString S, SString T, int pos ) {
// printf("%c\n",S[0]);
int len = strlen(S)-1;
int length=strlen(T)-1;
int i,j;
i = pos ;
j = 1;
while ( i<=len&&j<=length) {
if ( S[i] == T[j] ) {
++i;
++j;
}
else {
i = i -j + 2;
j = 1;
}
}
if ( j > length)
return i-length; // T在S中的匹配起始位置
else
return 0;
}
void main(){
SString s="6family",t="2am";
int x=0;
x=Index(s,t,1);
printf("%d",x); //2
getchar();
}