DIY Func same as strchr()

#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;
 }
}

你可能感兴趣的:(职场,休闲,strchr)