首页 > 编程语言 > 详细

【C语言】自己编写程序实现strrchr函数,即在给定字符串中找特定的字符并返回最后出现的位置

时间:2015-04-10 18:02:20      阅读:291      评论:0      收藏:0      [点我收藏+]
//自己编写程序实现strrchr函数,即在给定字符串中找特定的字符并返回最后出现的位置
#include <stdio.h>
#include <string.h>
char * my_strrchr(char const *str,int ch)
{
	int count=0;
	while(*str!='\0')
	{
		count++;
		str++;
	}
	str--;
	while(count)
	{
		if(*str!=ch)
		{
			str--;
			count--;
		}
		else
			return str;
	}
	printf("未找到该字符。\n");
	return 0;
}
int main()
{
	char *p="abcdefabcdef";
	char a;
	printf("请输入您要查找的字符:");
	scanf("%c",&a);
	printf("%s\n",my_strrchr(p,a));
	return 0;
} 

技术分享

技术分享

【C语言】自己编写程序实现strrchr函数,即在给定字符串中找特定的字符并返回最后出现的位置

原文:http://blog.csdn.net/doudouwa1234/article/details/44980973

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!