This blog is under construction

Sunday, 29 April 2012

strrchr example in C

Header file:

     char *strrchr(char *str, int c);
     On success, it returns pointer to the last occurrence of character c in string str.  Otherwise, NULL is returned.

strrchr function C example:


  int main() {
        char input[100], ch, *strloc;
        printf("enter your input:");
        fgets(input, 50, stdin);

        printf("enter your char input:");
        ch = getchar();
        strloc = strrchr(input, ch);
        printf("Output: %s\n", strloc);
        return 0;

  jp@jp-VirtualBox:~/cpgms/chap5$ ./a.out
  enter your input:world wide web
  enter your char input:w
  Output: web

No comments:

Post a Comment