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";
3
Contributors
5
Replies
7
Views
4 Years
Discussion Span
Last Post by hwoarang69
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

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"};
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.