
#include<stdio.h>
#include<string.h>
void search(char strSource[],char c)//查找这样的字符和输出功能
{
int i=0;
int indexPos=-1;//记录位置,-1代表不是正常位置,找的时候如果找到了正常位置就变更为1
while(strSource[i]!='\0')//找到‘\0’结束
{
//当前字符是不是我们要找的字符
if(c==strSource[i])
{
indexPos=i;//要找到最大的,所以不能break
}
i++;
}
//判断这样的字符存在不存在
if(indexPos==-1)
{
printf("Not Found\n");
}else{
printf("index = %d\n",indexPos);
}
}
int main()
{
char c;
char strSource[81];//不超过80个字符,是不含\0,所以最长是81个字符
c=getchar();
getchar();
gets(strSource);//输入字符到数组里,并且会自动给它加\0
search(strSource,c);
return 0;
}
来源:https://www.cnblogs.com/jiangzenghui/p/12603111.html