指针作为函数返回值

#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("末找到 ");

  }

  else

  {

    printf("%s ",p);

  }

  return EXIT_SUCCESS;

//结果1

 

 

//结果2

 

}

原文地址:https://www.cnblogs.com/wanghong19991213/p/13573804.html