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 ‘′ 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;
}

Related posts:

  1. Strstr Implementation in C
  2. Strncpy Implementation in C

Comments are closed.