Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C - <b>strrchr() scan string for last occurrence of character</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
strrchr()                Scan String for Last Occurrence of Character

 #include   <string.h>                   Required for declarations only

 char       *strrchr(string,ch);
 char       *string;                     Search string
 int        ch;                          Character to be located

    strrchr() scans 'string' in a reverse direction, looking for the last
    occurrence of the character 'ch'.  The terminating null character
    ('\0') is included in the search.

    Returns:    A pointer to the last occurrence of 'ch in 'string.  If
                the character is not found in 'string', a NULL pointer is
                returned.

  -------------------------------- Example ---------------------------------

    The following statements find the last occurrence of 'ch' in
    'string'.

          #include <string.h>
          #include <stdio.h>

          char *string = "How now, brown cow.";
          int ch = 'b';
          char *rslt;

          main()
          {
              if ((rslt = strrchr(string,ch)) != NULL)
                 printf("character found: %c\n",*rslt);
              else
                 printf("character not found.\n");
          }

See Also: strchr() strpbrk()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson