title: Check for substring in a buffer
body: <p>I use a buffer to receive data from a serial port. The buffer has a fixed length which is 100 and when I receive data I store the length of this data in a variable (index).</p>
  
  <p>I would like to check if the buffer from 0 to index-1 contains a substring.</p>
  
  <p>I've read that I could possibly do it using strstr and strdup but I have two issues with this.
  First I don't know how to extract a string from buffer and second it would be better if I didn't have to copy the string just to delete it one line later when I look for a substring in it.</p>
  
  <p>My variables are the following:</p>
  
  <pre><code>char output[100];
  int index = 0;
  char* substring;
  </code></pre>
  
  <p>And I'd like a function that would return true if substring is in output[0:index] and false otherwise.</p>
  
  <p>Any help or lead would be very appreciated!</p>
  
  <p>Edit: I'm writing a piece of code for an atmel µC so it seems as I'm limited to <a href="http://www.nongnu.org/avr-libc/user-manual/group__avr__string.html#ga8569f20e38a030b5a28fd951abec2c9b" rel="nofollow">those functions</a>.</p>
  
  <p>Edit 2: Actually it seems like I can use all the functions from the standard string.h</p>
  
  <p>Edit 3: I checked for sure in my dependencies and under are all the functions I can call.</p>
  
  <pre><code>extern int ffs (int __val) __ATTR_CONST__;
  extern int ffsl (long __val) __ATTR_CONST__;
  extern int ffsll (long long __val) __ATTR_CONST__;
  extern void *memccpy(void *, const void *, int, size_t);
  extern void *memchr(const void *, int, size_t) __ATTR_PURE__;
  extern int memcmp(const void *, const void *, size_t) __ATTR_PURE__;
  extern void *memcpy(void *, const void *, size_t);
  extern void *memmem(const void *, size_t, const void *, size_t) __ATTR_PURE__;
  extern void *memmove(void *, const void *, size_t);
  extern void *memrchr(const void *, int, size_t) __ATTR_PURE__;
  extern void *memset(void *, int, size_t);
  extern char *strcat(char *, const char *);
  extern char *strchr(const char *, int) __ATTR_PURE__;
  extern char *strchrnul(const char *, int) __ATTR_PURE__;
  extern int strcmp(const char *, const char *) __ATTR_PURE__;
  extern char *strcpy(char *, const char *);
  extern int strcasecmp(const char *, const char *) __ATTR_PURE__;
  extern char *strcasestr(const char *, const char *) __ATTR_PURE__;
  extern size_t strcspn(const char *__s, const char *__reject) __ATTR_PURE__;
  extern char *strdup(const char *s1);
  extern size_t strlcat(char *, const char *, size_t);
  extern size_t strlcpy(char *, const char *, size_t);
  extern size_t strlen(const char *) __ATTR_PURE__;
  extern char *strlwr(char *);
  extern char *strncat(char *, const char *, size_t);
  extern int strncmp(const char *, const char *, size_t) __ATTR_PURE__;
  extern char *strncpy(char *, const char *, size_t);
  extern int strncasecmp(const char *, const char *, size_t) __ATTR_PURE__;
  extern size_t strnlen(const char *, size_t) __ATTR_PURE__;
  extern char *strpbrk(const char *__s, const char *__accept) __ATTR_PURE__;
  extern char *strrchr(const char *, int) __ATTR_PURE__;
  extern char *strrev(char *);
  extern char *strsep(char **, const char *);
  extern size_t strspn(const char *__s, const char *__accept) __ATTR_PURE__;
  extern char *strstr(const char *, const char *) __ATTR_PURE__;
  extern char *strtok(char *, const char *);
  extern char *strtok_r(char *, const char *, char **);
  extern char *strupr(char *);
  </code></pre>