Using strchr : strrchr « string.h « C Tutorial






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

int main()
{
   const char *string = "This is a test";
   char character1 = 'a';
   char character2 = 'z';
   
   if ( strchr( string, character1 ) != NULL ) {
      printf( "\'%c\' was found in \"%s\".\n", 
         character1, string );
   } else { 
      printf( "\'%c\' was not found in \"%s\".\n", 
         character1, string );
   }

   if ( strchr( string, character2 ) != NULL ) {
      printf( "\'%c\' was found in \"%s\".\n", 
         character2, string );
   } else { 
      printf( "\'%c\' was not found in \"%s\".\n", 
         character2, string );
   } 

   return 0;

}
'a' was found in "This is a test".
'z' was not found in "This is a test".








24.18.strrchr
24.18.1.strrchr
24.18.2.Using strchr