Strchr implemention in C

Strchr – find first occurrence of a character in a string.
strchr returns a pointer to the first occurrence of the character “c” in the string “s”. The ‘\0’ that terminates
Syntax: ptr = strchr( s, c );
char *s: points to the string that is to be scanned for the presence of the character.
int c: is the character to look for.
char *ptr: points to the first occurrence of the character in the string. If the character does not appear in the string, the NULL pointer is returned.

char *strchr(const char *s, int c){
    while (*s != (char)c)
    if (!*s++)
        return 0;
    return (char *)s;
}

About mohan

This is Mohan Jayapalan author of TechPages Blog.I am a part time blogger and Currently working for private Software Concern.

© Copyright 2010-2016 www.techpages.org · All Rights Reserved · Powered by WordPress ·