zoukankan      html  css  js  c++  java
  • C语言之strrchr函数

    from:http://blog.csdn.net/hgj125073/article/details/8443912

    【FROM MSDN && 百科】

    原型:char *strrchr(const char *str, char c);

    #include<string.h>

    找一个字符c在另一个字符串str中末次出现的位置(也就是从str的右侧开始查找字符c首次出现的位置),并返回从字符串中的这个位置起,一直到字符串结束的所有字符。如果未能找到指定字符,那么函数将返回NULL。

    The strrchr function finds the last occurrence of c (converted to char) in str. The search includes the terminating null character.

     

    DEMO:

     

    [cpp] view plain copy
     
    1. #include <stdio.h>  
    2. #include <conio.h>  
    3. #include <string.h>  
    4. #pragma warning (disable:4996)  
    5. int main(void)  
    6. {  
    7.     char string[20];  
    8.     char *ptr;  
    9.     char c='r';  
    10.     strcpy(string,"There are two rings");  
    11.     ptr=strrchr(string,c);  
    12.     //ptr=strchr(string,c);  
    13.     if (ptr!=NULL)  
    14.     {  
    15.         printf("The character %c is at position:%s ",c,ptr);  
    16.     }  
    17.     else  
    18.     {  
    19.         printf("The character was not found ");  
    20.     }  
    21.     getch();  
    22.     return 0;  
    23. }  
  • 相关阅读:
    Python生成器
    Python迭代器
    Python异常处理
    Python面向对象进阶
    Python面向对象基础
    Python闭包和装饰器
    Python函数
    Python文件操作
    Python深浅拷贝
    Python的列表&元组&字典&集合
  • 原文地址:https://www.cnblogs.com/the-tops/p/5685861.html
Copyright © 2011-2022 走看看