strchr()查找字符串首次出现字符‘X’的位置

      #include
#include
#include


char * my_strchr(char *str,char x); 
char * my_strchr( char *str,char x)
{
    assert(str != NULL);
    for(;*str != x;str++)
    {
         if(*str == '\0')
         {
             return NULL; 
         }
    }
    return str;
}
int main()
{

    char str[] = "liusenlin";

   char * result  = NULL;
   result = my_strchr(str,'s');
    printf("%c %p \n",*result ,result);
    return 0;
}

运行结果:
s 0018FF3F
Press any key to continue

你可能感兴趣的:(c)