How to use strchr() library function in C

1 Answer

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

// char *strchr(const char *str, int c) 
// search for the first occurrence of a character in a string 
// return a pointer to the first occurrence of the character or NULL if the character is not found
  
int main(int argc, char **argv) 
{
    char s[] = "c programming"; 
      
	puts(strchr(s, 'm'));  
	puts(strchr(s, 'x')); // NULL 
	  
    if (strchr(s, 'p'))
        printf("Exist\n");
    else
        printf("Not Exist\n");
      
    return 0;
}
   
 
     
/*
run:
   
mming
Exist
   
*/
  

 



answered Jan 11, 2020 by avibootz

Related questions

1 answer 131 views
131 views asked Dec 16, 2022 by avibootz
2 answers 211 views
211 views asked Jun 28, 2024 by avibootz
1 answer 150 views
1 answer 121 views
121 views asked Aug 16, 2024 by avibootz
...