C语言字符串检索:查找指定字符并返回位置
#include<stdio.h> #include<string.h> #define N 81 int main() { static char str[N],ch; int i, position = -1; gets(str); scanf("%c","&ch"); for(i=0; i<strlen(str); i++) { if(str[i] == ch) { position = i; break; } } printf("%d", position);
return 0;
}
原文地址: https://www.cveoy.top/t/topic/pfIV 著作权归作者所有。请勿转载和采集!