#include<stdio.h> #include<string.h> int stringMatching(char* pattern, char* text){ int j=0; int pLen=strlen(pattern); int tLen=strlen(text); for(int i=0;i<=tLen-pLen;i++){ for(j=0;j<=pLen;j++){ if (pattern[j]==text[i+j]) return i; }; } return -1;//Not Found } int main(){ char a[200]; char b[100]; int i_pos; printf("请输入一行字符,在100个字以内/n"); gets(a); printf("请再输入一行字符,比前者长/n"); gets(b); i_pos=stringMatching(a,b); printf("%d",i_pos); } 在后一个字符串中找寻前一个字符串的首字母匹配,并没有达到字符串匹配的效果。