C/Memory/Memory Search

Материал из C\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;
}