字符串查找

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

//使用系统函数strchr在字符串中查找字符

int main0101()

{

  char ch[]="hello world";

  char c='l';

  char*p=strchr(ch,c);

  printf("%s ",p);//llo world

  return EXIT_SUCCESS;

}

//自定义函数在字符串中查找字符

char*my_strchr(const char*ch,int c)

{

  while(*ch)

  {

    if(*ch==c)

    {

      return ch;

    }

    ch++;

  }

  return NULL;  

}

int main0102(void)

{

  char ch[]="hello world";

  char c='1';

  char*p=my_strchr(ch,c)

  printf("%s ",p);//llo world

}

//使用系统函数strstr在字符串中查找字符串

int main(void)

{

  char ch[]="hello world";

  char str[]="llo";

  char*p=strstr(ch,str);

  printf("%s ",p);//llo world

  return 0;

}

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