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. }  
  • 相关阅读:
    【JAVA与C#比较】其它
    C#和java之间的一些差异与共性
    C#与Java的语法差异
    关于npm本地安装模块包(node_modules),安装不了的问题
    vue
    vue
    vue
    vue
    v
    vue -model
  • 原文地址:https://www.cnblogs.com/the-tops/p/5685861.html
Copyright © 2011-2022 走看看