用指针的方式实现,重写strrchr函数的功能

char *strchrTest(char * ptr,char c);

Action()
{
char str[]={"thisisadog"};
char c='s';
lr_output_message("%s",strchrTest(str,c));

return 0;
}
char *strchrTest(char *ptr,char c)
{
char *p=ptr;
char *p1=ptr;

if(ptr!=NULL)
{
//移动指针到字符串尾
while(*ptr!='')
{
ptr++;
}

//逆向查找指定字符
while(ptr!=p1)
{
if(*ptr==c)
{
p=ptr;
break;
}
ptr--;
}
}

//实现大写到小写的转化;
if((*p>='A')&&(*p<='Z'))
{
}
else if ((*p>='a')&&(*p<='z'))
{
*p=*p-32;

}else
{
lr_output_message("%c不是字母",c);
}

//lr_output_message("%s",ptr);

return p;
}

原文地址:https://www.cnblogs.com/NiceTime/p/9192607.html