Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo C ) - <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 first occurrence of 'ch' in 'string'.  The
    terminating null character ('\0') is included in the search.
    strchr() is case sensitive.

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

         Notes:     strchr() expects to operate on null-terminated
                    strings.  No overflow checking is done when strings
                    are copied or appended.

   -------------------------------- 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