Skip to content

Instantly share code, notes, and snippets.

@samcv
Created April 6, 2017 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samcv/60469bf4ea8db41db3f21d95c2f8a957 to your computer and use it in GitHub Desktop.
Save samcv/60469bf4ea8db41db3f21d95c2f8a957 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
int main (void) {
void * haystack = "abcdaaa";
void * needle = "aa";
int m = memmem(haystack, 7, needle, 1 );
printf("haystack[%lu] needle[%lu] found[%lu]\n",
haystack,
needle,
m );
char * mm = (char *) memmem(haystack, 7, needle, 1 );
printf("%c%c%c\n",
mm, mm+1, mm+2
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment