const char** is incompatible with parameter of type const char*

Hi,
I was working at making a really basic game of cards but when i call the function couple(face) it says:
Error (active) E0167 argument of type "const char **" is incompatible with parameter of type "const char *"

when i try using face in couple (the first if) it says:
Error (active) E0513 a value of type "char" cannot be assigned to an entity of type "char *"

at the second if whit if it says:
E0042 operand types are incompatible ("char" and "char *")
I work on visual studio.
Thanks in advance for your help!


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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
void DeckOfCards::deal()
{
	static const char* suit[4] = { "Hearts", "Diamonds", "Clubs", "Spades" };
	static const char* face[13] = { "Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" };


	for (int card = 1; card <= 5; card++)
	{
		for (int row = 0; row <= 3; row++)
		{
			for (int column = 0; column <= 12; column++)
			{
				if (deck[row][column] == card)
				{
					cout << setw(5) << right << face[column] << " of " << setw(8) << left << suit[row] << (card % 2 == 0 ? '\n' : '\t');
				}
			}
		}
	}
	couple(face);
}

bool DeckOfCards::couple(const char* face) 
{
	int uguale = 0;
	char* conf[1] = { "Seven" };// here it says E0144 a value of type //"const char *" cannot be used to initialize an entity of type "char *"


	for (size_t card = 1; card <= 5; card++)
	{
		for (size_t row = 0; row <= 3; row++)
		{
			for (size_t column = 0; column <= 12; column++)
			{
				if (deck[row][column] == card)
				{
					conf[1] = face[column];
				}
			}
		}
		for (size_t row = 0; row <= 3; row++)
		{
			uguale = 0;
			for (size_t column = 0; column <= 12; column++)
			{
				if (deck[row][column] == card)
				{
					if (face[column] == conf[1])
						uguale++;

					if (uguale == 2)
						return true;
				}
			}
		}
	}
	return false;
}
Please make a minimal compilable example of your problem.

The compiler errors should be solve with an additional const:

const char* conf[1] = { "Seven" };

On line 48 you compare pointer (which are certainly differnt). To compare c-strings you need strcmp(...).
char* conf[1] = { "Seven" };
The "Seven" is a constant string literal. Those six bytes are in special part of the executable.
It is a huge error to attempt to modify that memory.
What the compiler actually gives us is the address of the first character in that block. The address of 'S'.

In other words, your code does:
1
2
const char* literal = "Seven";
char* conf[1] = { literal };


The conf is an array of pointers. Array that has only one element. One pointer.
If you did not have an array, then your code would be:
1
2
const char* literal = "Seven";
char* one = literal;

The literal has a memory address. You want to store the address in one.
The both literal and one point to same constant string literal.

However, one is not const. It would be syntactically legal to modify via one:
one[2] = 'X'; // would change "Seven" to "SeXen".
However, it is not legal to modify constant string literal.


The standard "C++ advice" is to use std::string and not C-strings.
1
2
3
4
if (deck[row][column] == card)
				{
					conf[1] = face[column];
				}


conf has only 1 element - and indexes start at 0 - so to access it:

1
2
3
4
if (deck[row][column] == card)
{
	conf[0] = face[column];
}


The same with the access at line 48.

Also, as conf is of type char* you can't assign face[column] which is of type char.
Topic archived. No new replies allowed.