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

来源:互联网 发布:iphone网络共享在哪里 编辑:程序博客网 时间:2024/04/30 08:34
#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
原创粉丝点击