#define_CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<assert.h>char*strchr(char*str,char ch){char*ret=NULL;assert(str);while(*str){while(ch){if(*str==ch){
ret=str;return ret;}
str++;}returnNULL;}}intmain(){char*string="hello my college";int ret=0;char ch=0;printf("please enter the ch:\n");scanf("%c",&ch);
ret=(char)strchr(string,ch);//ret=(char)find(string);printf("%d\n",ret);system("pause");return0;}
在字符串中查找一个特定的字符最后一次出现的位置,并返回字符所在位置
#define_CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<assert.h>char*strrchr(char*str,char ch){char*ret=NULL;assert(str);while(*str){if(*str==ch)
ret=str;
str++;}return ret;}intmain(){char*string="hello my college";int ret=0;char ch=0;printf("please enter the ch:\n");scanf("%c",&ch);
ret=(char)strrchr(string,ch);printf("%d\n",ret);system("pause");return0;}