Luga
Luga

Reputation: 121

C array of pointers to strings, passing string from pointer

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.

Upvotes: 1

Views: 99

Answers (1)

Gopi
Gopi

Reputation: 19874

int strncmp(char *string1, char *string2, int n);

This is the prototype of strncmp()

In your case pass

strncmp("somestring",p,n); /* n = number of characters to be compared */

Upvotes: 2

Related Questions