实验求帮助
输入一个字符,再输入一个以回车结束的字符串,少于 80个字符,在字符串中查找该字符。如果找到,则输出该字符在字符串中所对应的最大下标,下标0开始,否则输出 没找到
[解决办法]
#include <stdio.h>#include <string.h>int main(){ char a[81]; char b[81]; int LengA,LengB; int i,j; scanf("%s",a); scanf("%s",b); LengA =strlen(a); LengB=strlen(b); i = 0; j = 0; while(i<LengA && j<LengB) { if (a[i]==b[j]) { j++; } else { i = i - j ; j = 0; } i++; if(j==LengB) break; } if(j==LengB) printf("Find it ! At %d\n",(i-j-1)); else printf("Not Find it\n"); return 0;}