#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define SIZE 20
char *doSearch(char context[],char getchar);
int main(void){
char context[SIZE];
char wantchar;
char *re;
puts("Input a string:");
gets(context);
puts("Input a char:");
wantchar=getchar();
re=doSearch(context,getchar);
if(re){
printf("%c is founded in position %p\n",*re,re);
}else{
printf("Nothing found.\n");
}
}
char *doSearch(char context[],char wtchar){
char *ps;
ps=context;
while(ps&&*ps!=wtchar){
ps++;
}
if(*ps==wtchar){
return ps;
}else{
return NULL;
}
}
转载于:https://blog.51cto.com/pnig0s1992/428227