I am trying to copy substring of s to pointer to an array of strings. And below is my code. I have allocated the memory using malloc. But when I try to perform strncpy, I get segmentation fault. Can anyone please let me know if there is anything wrong with my code? Or is it allowed to strncpy on a array of pointers to strings
s is a string of length 32
char **suptr = (char **)malloc(sizeof(char *) * 11);
if(suptr != NULL)
{
strncpy(suptr[0], s, 10);
strncpy(suptr[1], s+10, 10);
strncpy(suptr[2], s+20, 10);
strncpy(suptr[3], s+30, 2);
}
Thanks in advance
malloc.s?s