#include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <curses.h> int getline_(char *s,int n) { char c; char *sta = s; while(--n > 0 && (c = getchar()) != EOF && c != ' ') { *s++ = c; } if(c == ' ') *s++ = c; *s = ' '; return s - sta; } int atoi_(char *s) { int n,sign; for(;isspace(*s);s++) ; sign = (*s == '-') ? -1 : 1; if(*s == '+' || *s == '-') s++; for(n = 0;isdigit(*s);s++) n = 10 * n + *s - '0'; return sign * n; } void reverse_(char *s) { int temp; char *t; for(t = s + strlen(s) - 1;s < t;s++,t--) { temp = *s; *s = *t; *t = temp; } } void itoa_(int n,char *s) { int sign; char *t = s; if((sign = n) < 0) n = -n; do { *s++ = n % 10 + '0'; }while((n /= 10) != 0); if(sign < 0) *s++ ='-'; *s = ' '; reverse_(t); } int strindex_(char *s,char *t) //返回最右边出现的位置 { char *sta = s; char *p,*r; int n = -2; for(;*s != ' ';s++) { for(p = s,r = t;*r != ' ' && *p == *r;p++,r++) ; if(r > t && *r == ' ') n = s - sta; } if(n != -2) return n; else return -1; } int main() { char p[] = "abcdefgab",q[] = "uh"; int n; n = strindex_(p,q); printf("%d",n); return 0; }