1.11M Members

quick question on array of pointers.

 
0
 

i want to create array of pointer. "aa" "ab" "ac"

i tried many thing but it still give me error.

char *table[3] = "aa", "ab", "ac";

or

char *table[3];
*table[0] = "aa";
*table[1] = "ab";
*table[2] = "ac";
 
0
 

try something like this:

  char *array[3];
  char x = 'a', y = 'b', z = 'c';

  array[0] = &x;
  array[1] = &y;
  array[2] = &z;

  for (int i=0; i< 3; i++) 
      printf( "%d = %c\n", i, *(array[i]) );
 
0
 

hm.. dont work

 
0
 

got it to work with windows using cygwin and linux gcc...
is there a specific error or output that happens when you compile or run the code?

 
0
 

i want to create array of pointer. "aa" "ab" "ac"

You've forgotten brackets .. {}, i.e.

const char *table[3] = {"aa", "ab", "ac"};
 
0
 

oh right, thanks :)

Isn't it about time forums rewarded their contributors?

Earn rewards points for helping others. Gain kudos. Cash out. Get better answers yourself.

It's as simple as contributing editorial or replying to discussions labeled or OP Kudos

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: