strchr() seems a more appropriate choice that strstr().
Use the result of first strchr(), + 1, as the argument to a subsequent strchr() and then malloc() and strcpy() or sprintf() into a[1]:
#include <stdio.h> #include <string.h> #include <stdlib.h> int main() { char* a[10]; char* p; a[0] = "'example'"; p = strchr(a[0], '\''); if (p) { char* q = strchr(++p, '\''); if (q) { a[1] = malloc((q - p) + 1); if (a[1]) { sprintf(a[1], "%.*s", q - p, p); printf("[%s]\n", a[1]); } } } return 0; }
Storing pointers to string literals and malloc() data into the same array seems a dangerous thing to do. You must free() dynamically allocated memory, but only dynamically allocated memory. The code will need to know what elements in a are pointing at dynamically allocated memory, and must be free()d, and those that are not.
Initialise a to all NULLs, so it is known what elements are populated:
char* a[10] = { NULL };
and calling free() on a NULL pointer is safe (does nothing).
if (p) a[1] = p + 1;makes a[1] point to just after the first'. You need some way to find the next'inside that string.