This blog is under construction

Sunday, 29 April 2012

strrchr example in C

Header file:
    string.h

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


strrchr function C example:


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

  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;
  }




  Output:
  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