This blog is under construction

Sunday 29 April 2012

strchr example in C

Header file:
    string.h

Synopsis:
   int strchr(char *str, int c);

Description:
     It locates character c in string str.  On success, it returns pointer to the first occurrence of character c in string str.  Otherwise, NULL is returned.


strchr 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 = strchr(input, ch);
        printf("Output: %s\n", strloc);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  enter your input:see-programming.blogspot.com
  enter your char input:b
  Output: blogspot.com 

No comments:

Post a Comment