Search buffer for a character: how to use memchr : Memory Search « Memory « C / ANSI-C






Search buffer for a character: how to use memchr


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

int main ()
{
  char *p;
  char str[] = "An Example string";
  
  p = (char*) memchr (str, 'l', strlen(str));
  
  if (p != NULL)
    printf ("Character l was at position %d.\n", p - str + 1);
  else
    printf ("Character l was not found");
  return 0;
}

           
       








Related examples in the same category