





#include<stdio.h> #include<string.h> int main() { char m,s[81]; int i,index; printf("Input a character:"); scanf("%c",&m); getchar(); //就是这里,吸收回车 printf("Input a string:"); gets(s); for(i=0;i<strlen(s);i++) { if(s[i]==m) index=i; } printf("index=%d\n",index); return 0; }
[此贴子已经被作者于2016-5-19 15:01编辑过]