在字符串中查找一个特定的字符最后一次出现的位置(即最右边那个)

来源:互联网 发布:网络机顶盒品牌排行 编辑:程序博客网 时间:2024/04/19 08:20



#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;
}

0 0
原创粉丝点击