Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>strchr() find a character in a string</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 strchr()                Find a Character in a String

 #include   <string.h>                   Required for declarations only

 char       *strchr(string,ch);
 const char *string;                     Source string
 int        ch;                          Character to be found

    strchr() finds the occurrence of 'ch' in 'string'.  strchr() is case
    sensitive and includes the terminating null character ('\0') in the
    search.

    Returns:    A pointer to the character, if found; NULL if 'ch' is not
                found.

      Notes:    strchr() expects to operate on null-terminated strings.

   -------------------------------- Example ---------------------------------

    This example searches for a lowercase 'a' in 'str'.

           #include <string.h>
           #include <stdio.h>            /* for printf */

           char str[50] = "All in a good day's work.";
           int ch = 'a';
           char *rslt;

           main()
           {
                 if ((rslt = strchr(str,ch)) != NULL)
                    printf("character found: %c  \n",*rslt);
                 else
                    printf("character not found.");
           }


See Also: strrchr() strpbrk()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson