I have an array of pointers to strings (char ** array), and I have a pointer, which points somewhere into this array (for example, third char of array[0]). I need use strncmp, where as second argument, I would pass string starting from where the pointer is.
i.e.:
char ** array = (char**) malloc (sizeof(char*)*count);
array[0] = "Hello World";
char * p = array[0] + 3; /* just for example */
strncmp(query, ?, somemagicnumber);
what '?' should contain, in this case, 'lo World' (p points to second l in Hello);
How do I do this? Is it even possible?
Thanks for your help.
strncmp(query, p, somemagicnumber);
? – Edwardarray[0] = "Hello World"
expression is wrong, to copy the string intoarray[0]
usestrcpy(array[0], "Hello World")
. Since you are doing thisarray[0] = malloc(n)
. And hence you are overwritingarray[0]
with another address. – Iharob Al Asimimalloc
, or usestrcpy
like iharob suggests. – Sergey Kalinichenko