Thread: strrchr

  1. #1
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248

    strrchr

    Hi everyone,

    Does anyone know why the old C function "strrchr" has been implemented in C++ as

    Code:
    const char * strrchr ( const char * str, int character );
          char * strrchr (       char * str, int character );
    and not as

    Code:
    char * strrchr ( const char *, int );
    Some old C libraries won't compile anylonger...

    Thanks!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    strrchr returns a pointer to the character found (or a null pointer otherwise). As such, it makes sense that if you pass it a pointer to something that should not be changed, you get back a pointer to something that should not be changed.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 05-28-2009, 09:30 AM
  2. strrchr help
    By newcguy in forum C Programming
    Replies: 6
    Last Post: 06-05-2007, 04:25 PM
  3. Counting characters
    By Calavera in forum C Programming
    Replies: 5
    Last Post: 10-01-2004, 10:15 AM