Reputation: 35
I have a character array. A pointer points to that character array. Also, another pointer points to that pointer i.e. it is a pointer to a pointer. Now, I need to compare the pointer to the pointer with a character literal, say "a".
I tried strcmp but it didn't work.
How can I do this?
char arr[1000];
char *ptr,*ptr1,**curr;
ptr=arr; //pointer pointer to that array
curr=&ptr; //pointer to a pointer
if(**curr=='.') //doesn't work
printf("Some code");
Upvotes: 1
Views: 100
Reputation: 310930
If I have understood correctly you are speaking about the following
#include <string.h>
//...
char arr[1000] = "a";
char *ptr = arr;
char **curr = &ptr;
if ( strcmp( *curr, "a" ) == 0 ) puts( "They are equal" );
Or
#include <string.h>
//...
char arr[1000] = "abcd";
char *ptr = arr;
char **curr = &ptr;
char *ptr2 = "ab";
if ( strncmp( *curr, ptr2, strlen( ptr2 ) ) == 0 ) puts( "They are equal" );
If you need to compare a single character then you can write
char arr[1000] = "a";
char *ptr = arr;
char **curr = &ptr;
if ( **curr == 'a' ) puts( "They are equal" );
or
char arr[1000] = "ab";
char *ptr = arr;
char **curr = &ptr;
if ( ( *curr )[1] == 'b' ) puts( "They are equal" );
Upvotes: 4