您的位置:首页 > 其它

[置顶] 在字符串中查找一个特定的字符最后一次出现的位置,并返回字符所在位置。

2016-10-26 18:20 489 查看
#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;
}

int main()
{
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");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐