Search char in an exat string with pointer

So simple,just for ex.

  
  
  
  
  1. #include <stdio.h> 
  2. char *find_char(char const *source,char const *chars); 
  3. int main(void){ 
  4.     char *source="hellopnig0s"
  5.     char *chars="epg0"
  6.     char *result; 
  7.     result=find_char(source,chars); 
  8.     if(result){ 
  9.         printf("We found %c in position:%p\n",*result,result); 
  10.     }else
  11.         puts("Nothing be found."); 
  12.     } 
  13. char *find_char(char const *source,char const *chars){ 
  14.     char * check; 
  15.     while(*chars!='\0'){ 
  16.         while(*source!='\0'){ 
  17.             if(*source++==*chars){ 
  18.                 return source-1; 
  19.                 break
  20.             }else
  21.                 check=NULL; 
  22.             } 
  23.         } 
  24.         chars++; 
  25.     } 
  26.     if(!check){ 
  27.         return check; 
  28.     } 

 

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