Error LNK1120, LNK2019 - Passing values

Hi!

New to the forum, user of the website.

I'm currently coding a hangman game and I've run into the errors mentioned. I recently condensed my 5 levels of difficulty into 1 function which passes values, which i think where the code is originating from. I can't figure out for the life of me what the problem is..

The errors are:

LNK1120: 1 unresolved externals - Which i believe is to do with a function not being used/ referenced properly?

LNK2019: unresolved external symbol "void __cdecl game(char * const,char * const)" (?game@@YAXQAD0@Z) referenced in function "void __cdecl diff_select(int)" (?diff_select@@YAXH@Z)

LNK2019 is the error i can't figure out.. It's doing my head in!

Here's the relevant lines of code.
1
2
3
4
5
6
7
8
PART ONE

void display_intro01();
void display_intro02();
void diff_check();
void display_instructions();
void diff_select(int user_difficulty); 
void game(char hidden_word[], char select_word[]);


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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
PART TWO

void diff_select(int user_difficulty)
{
	char hidden_word[11]={0};
	char select_word[11]={0};
	
	cin.ignore();

	int exit_1 = 0;

	display_intro02();
	cout << "Good selection!\n To play, you must first choose a difficulty\n";
	cout << "Please type a number between 1 and 5. 5 being the hardest, 1 being the easiest.\n";
	cout << "Please enter your selection\n";

	//diff_check();
	
	cin >> user_difficulty;

	switch (user_difficulty)
	{
	case 1: game(hidden_word, select_word);
		Sleep(2000);
		break;
	case 2: game (hidden_word,select_word);
		Sleep(2000);
		break;
	case 3: game (hidden_word, select_word);
		Sleep(2000);
		break;
	case 4: game (hidden_word, select_word);
		Sleep(2000);
		break;
	case 5: game (hidden_word, select_word);
		Sleep(2000);
		break;
	}

}


void game(char hidden_word[], char select_word[], int user_difficulty)
{
	char diff_1[5][26] = {"names","great","three","white","music"};
	char diff_2[5][31] = {"accept", "booked", "desert", "gassed", "gallop"};
	char diff_3[5][36] = {"acrobat", "defiant", "gullies", "library", "nuttier"};
	char diff_4[5][41] = {"airbrush", "chunkier", "drunkest", "indulges", "mixtures"};
	char diff_5[5][49] = {"actionless", "cartooning", "descendent", "fistcuffs", "penthouse"};

	int array_size = 0;
	int null_found = 0;

	srand(time(0));
	int rand_number = rand()%5;

	if(user_difficulty == 1)
	{
		strcpy(hidden_word,&diff_1[rand_number][0]);
	}
	else if(user_difficulty == 2)
	{
		strcpy(hidden_word,&diff_2[rand_number][0]);
	}
	else if(user_difficulty == 3)
	{
		strcpy(hidden_word,&diff_3[rand_number][0]);
	}
	else if(user_difficulty == 4)
	{
		strcpy(hidden_word,&diff_4[rand_number][0]);
	}	
	else if(user_difficulty == 5)
	{
		strcpy(hidden_word,&diff_5[rand_number][0]);
	}

	int len=strlen(hidden_word);
	for(int i = 0; i <len; i++)
	{
		select_word[i]='*';
	}
	cout << "\nYour word is" << array_size << " Letters long." << select_word << endl;

	int life = 5;
	bool you_win = false;

	while( (life > 0) && (you_win == false) )
	{
		cout<<"Current Word :" <<select_word << endl;
		cout<<"Enter Letter guess: ";
		char guess;
		cin>>guess;

		int hit=0;

		for(int i=0; i<len; i++)
		{
			if( guess == hidden_word[i] )
			{
				hit++;
				select_word[i] = guess;
				if(strcmp(hidden_word,select_word) == 0)
				{
					you_win = true;
				}
			}

		}
		if(hit == 0)
		{
			life--;
		}
	}
	if( (life == 0) && (you_win == false) )
	{
		cout<<"Loser\n";

	}
	if( (life > 0) && (you_win == true) )
	{
		cout<<"Winner\n";
	}
}



These are the pieces of code which pass the values. I believe the problem lies within the 'user_difficulty' value, as that's the int which is part of the code i condensed. The code i condensed is PART TWO (function prototype - game). i had it C&P'd 5 times.. don't ask why. Time to DRY code.

Thanks for any help in advanced.
hiya,
From your part 1:
void game(char hidden_word[], char select_word[]);

and from your part 2:
void game(char hidden_word[], char select_word[], int user_difficulty)

see the difference? The signatures need to be the same. and the second game() function you've told the linker takes a 3rd parameter (which is actually does).

edit: you need to pass down your difficulty everytime you call game() in your switch statement. for example:

1
2
3
4
case 1: game(hidden_word, select_word, user_difficulty);
		Sleep(2000);
		break;
Last edited on
Hi Mutexe.

You're right! I passed it into 'game' which is part of part 2, at the top, as well.

Really don't know how i missed it.

Despite it being a small problem, i really appreciate the help. Thanks.

Game works perfect now! time to add a GUI..
You're welcome dude.
Topic archived. No new replies allowed.