1、问题
编写一个叫my_strrchr(char *str, int ch)的函数,这个函数类似strchr函数,知识它返回的是一个指向ch字符在,str字符串中最后一次出现(最右边)的位置的指针
2、代码实现
#include <stdio.h>
#include <string.h>
/**
编写一个叫my_strrchr(char *str, int ch)的函数;
这个函数类似strchr函数,知识它返回的是一个指向ch字符在
str字符串中最后一次出现(最右边)的位置的指针
**/
char *my_strrchr(char *str, int ch)
{
if (str == NULL)
return NULL;
char *result = NULL;
while ((str = strchr(str, ch)) != NULL)
{
printf("*str is %c\n", *str);
result = str;
++str;
}
return result;
}
int main()
{
char *str = "chenyuenyuhello";
char ch = 'y';
printf("my_strrchr(%s, %d)