C strchr function

The C strchr function is a String Function, which returns a pointer to the first occurrence of a character in the given string. The syntax of the strchr is

void *strchr(const char *str, const char *chr_to_look);
  • str: A valid string
  • chr_to_look: Character value that you want to search inside str

strchr function in C Language Example

The strchr function searches for the first occurrence of a character within the user-specified string. This program will help you to understand the strchr with multiple examples.

TIP: You have to include the C Programming #include<string.h> header before using this String Function.

#include <stdio.h> 

int main()
    char str[] =  "C tutorial at tutorial gateway";
    char *ch;
    ch = strchr(str, 'i');
        printf("We Found your First Occurence of a Given Character");
        printf("\nThe Final String From 'b' is : %s \n", ch);
        printf("Given Character is Not found. Sorry!! \n");
    return 0;
C strchr example

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.