Use an array to call a defined variable

I had managed to get a variable to print out a #defined definition, but than I accidentally deleted the code and can not figure it out. I am hoping that someone may be able to point me in the right direction.

What I am getting is the 'aaa' and not 'one' to print. I know I am doing something wrong, but I can not see it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  #include <iostream>
#include <cstring>

#define aaa "One"
#define aab "Two"
#define aac "Three"

using namespace std;

int main()
{
	char Print[5];
	char *Array[3][5];

	*Array[0] = "aaa";
	*Array[1] = "aab";
	*Array[2] = "aac";

	for (int x = 0; x < 3; x++)
	{
		strcpy_s(Print, *Array[x]);

		cout << Print << endl;
	}

	system("pause");
	return 0;
}
"aaa" is the STRING literal "aaa"
aaa without quotes is your macro.

so you want
*Array[0] = aaa; // no quotes.
yea sorry that was a bad explanation and sample code. What I am trying to do is find a way to automate that so I do not have to turn the 'aaa' into a for loop that can call it instead of me having to type out aaa, aab, aac . . . every time.
automate what exactly?
Be very precise what you want the code to DO.


What it is suppose to be is a three digit alpha code that is assigned to the defined definition. when I start up the program it will assign 'aaa, aab, aac, ect' into an Array[x][x]. Than later in the program when it is printed to the screen instead of seeing 'aaa' you would instead see the #defined code, 'one' in the above code. I had this working before, but accidentally deleted the code and have been stuck for the last twoish days.

edit:
essentially I do not want to have to type aaa - zzz to add it to the array one line at a time. which i know how to do, but I can not get it to print out the defined value
Last edited on
you "could" make function pointer array out of Array[] to do it, I *think*. This isn't anything I would attempt to do, but I am fairly sure it would be possible with some effort.

But this feels like you should just use a <map> or an array of structs with both values or something to avoid the uglies.

Last edited on
Ok thanks I will look into that.
Topic archived. No new replies allowed.