Showing posts with label strchr example in c. Show all posts
Showing posts with label strchr example in c. Show all posts

Friday, October 2, 2020

, , ,

strchr function in c with program example

strchr example in c

strchr function in c programming find the first appearance of the character in the string.
 
strchr function in c with program example
strchr function in c with program example

 
 
 The character in c programming function can be null character (/0) and the ending null char. also include in this string search. 
 
A string argument also contain the null character so that the end of the string can be noticed.
 
Return value for strchr program in c  

strchr function return a pointer if specified character are appears in the given string otherwise it return the NULL.
 

Example Program for strchr function in c

 
#include <stdio.h>
#include <string.h>
 
 
int main(void)
{
  char buffer1[SIZE] = "computer program";
  char * ptr;
  int    ch = 'p';
 
  ptr = strchr( buffer1, ch );
  printf( "The first occurrence of %c in '%s' is '%s'\n",
            ch, buffer1, ptr );
 
}