指针作为函数返回值

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>

 

char* my_strchr01(char*str,char*ch)

{

  int i=0;

  while(str[i])

  {

    if(str[i]==ch)

    {

      return &str[i];

    }

    i++;

  }

  return NULL;

}

char* my_strchr(char*str,char*ch)

{

  while(*str)

  {

    if(*str==ch)

    return str;

    str++;

  }

  return NULL;

}

int main()

{

  char str[]="hello world";

  char*p=my_strchr(str,l);

  if(p=NULL)

  {

    printf("末找到\n");

  }

  else

  {

    printf("%s\n",p);

  }

  return EXIT_SUCCESS;

//结果1

 

 

 

 

//结果2

 

 

 

 

}

posted @ 2020-08-27 20:32  wh19991213  阅读(271)  评论(0编辑  收藏  举报