Easy Tutorial
❮ C Function Localeconv C Exercise Example43 ❯

C Library Function - strchr()

C Standard Library - <string.h>

Description

The C library function char *strchr(const char *str, int c) searches for the first occurrence of the character c (an unsigned char) in the string pointed to by the argument str.

Declaration

Here is the declaration for the strchr() function.

char *strchr(const char *str, int c)

Parameters

Return Value

The function returns a pointer to the first occurrence of the character c in the string str, or NULL if the character is not found.

Example

The following example demonstrates the use of the strchr() function.

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

int main ()
{
   const char str[] = "http://www.tutorialpro.org";
   const char ch = '.';
   char *ret;

   ret = strchr(str, ch);

   printf("String after |%c| is - |%s|\n", ch, ret);

   return(0);
}

Let's compile and run the above program, this will produce the following result:

String after |.| is - |.tutorialpro.org|

C Standard Library - <string.h>

❮ C Function Localeconv C Exercise Example43 ❯