Tuesday, 17 January 2012

C - memchr

#include <stdio.h>
void* memchr(const void* cs, int c, int n);
The memchr function scans cs for the character c in the first n bytes of the buffer.
Return Value
The memchr function returns a pointer to the character c in cs or a null pointer if the character was not found.
#include <stdio.h>
int main()
  char src [100] = "Search this string from the start";
  char *c;
  c = (char*)memchr (src, 'g', sizeof (src));
  if (c == NULL)
    printf ("'g' was not found in the src\n");
    printf ("found 'g' in the src\n");
  return 0;
It will proiduce following result:
found 'g' in the src

No comments:

Post a Comment

host gator coupon