Linking errors

I'm writing a code that decrypts certain text files using arrays.

There is a permutation of 20 integers, and it applies the permutation to a character string and decodes a message (from a given input file). Anyways, I'm getting a couple linking errors

: error LNK2019: unresolved external symbol "void __cdecl permutation(int * const,int const * const,int,int)" (?permutation@@YAXQAHQBHHH@Z) referenced in function _main

fatal error LNK1120: 1 unresolved external

The codes not yet complete but I want to figure out why this is happening, thanks. and sorry I haven't commented on it all

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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <iostream> // for cout, if needed for debugging
#include <fstream> // for file stream support
#include <iomanip> // for formatting support
#include <cmath> // for standard math functions, if needed
#include <string> // for character string type
using namespace std; // put all of that in scope

const int totalInt = 20;
void readpermutation (ifstream& Data, int readInt[], int idx);
void permutation (int readInt[], const int inverse[], int idx, int newIdx);
void readNumChar (ifstream& Data, int numChar);
void readMessage (ifstream& Data, char readChar[], int idx);
void decryption (char readChar[], int readInt[], int inverse[], char finished[], 
				  int idx, int newIdx);
void firstoutput (ofstream& Log, int numChar);
void secondoutput (ofstream& Log, int readInt[]);
void lastoutput (ofstream& Log, char finished[]);


int main () {
	int readInt[totalInt]; //reads and creates first array
	int inverse [totalInt]; //creates new array for decryption
	int numChar = 0; //number of integers given in the input
	char readChar[totalInt]; //array of the code needing decryption
	char finished[totalInt]; //final outputted array
	int sumChar = 0; //sum of characters
	int idx = 0; //index number
	int newIdx = 0; //new index number



	ifstream Data("Scrambled.txt"); // opens the input file
	ofstream Log("Unscrambled.txt"); // opens the output file

		readNumChar (Data, numChar); //read number of characters in the input

		firstoutput (Log, numChar); //first output

		readpermutation (Data, readInt, idx); //reat the permutation array

		secondoutput (Log, readInt); //second output

		readMessage (Data, readChar, idx); //read first 20 characters of the message

	
			while ( Data && sumChar < numChar) {

				for (idx = 0; idx < totalInt; idx++) {

				permutation (readInt, inverse, idx, newIdx);

				decryption (readChar, readInt, inverse, finished,  idx, newIdx);

				readMessage (Data, readChar, idx);
			
				}
			idx = 0;

			sumChar = sumChar + 20;

					
				
		}



			return 0;
}
	


//Function definitions:

	void readpermutation (ifstream& Data, int readInt[], int idx) { //read first line of digits


		Data.ignore(INT_MAX, '\n');	// skip first line of input
		Data >> readInt[idx]; // reads list of integers 
		
	}



	void permutation (int readInt[], int inverse[],int idx, int newIdx) {

				readInt[idx] = newIdx;	
				inverse[newIdx] = idx;
				
	}




	void decryption (char readChar[], int readInt[], int inverse[], char finished[], int idx, int newIdx) {
		
				
				readChar[idx] = readInt[idx];
				readChar[newIdx] = inverse[newIdx]; 
				
	}




	void readNumChar (ifstream& Data, int numChar) {

		Data.ignore(INT_MAX, '\n');	  //skip next 2 lines
		Data.ignore(INT_MAX, '\n');
		Data >> numChar;	//read how many characters in the message

	}


	void readMessage (ifstream& Data, char readChar[], int idx) {


				Data.ignore(INT_MAX, '\n'); // skip next 2 lines
				Data.ignore(INT_MAX, '\n');
				Data >> readChar[idx];
				idx = 0;
			}
		
	


	void firstoutput (ofstream& Log, int numChar) {
		Log << "***************************************************************************"
			<< "Decrypting " << numChar << " characters" << endl;
	}



	void secondoutput (ofstream& Log, int readInt[]){
		

		Log << "Using:  0  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18 19";
		Log << endl;
		Log << "         " <<  setw(3) << readInt << endl;

		 
		}
	
	


Last edited on
The prototype and implementation don't match:
1
2
3
4
5
6
void permutation (int readInt[], const int inverse[], int idx, int newIdx);

void permutation (int readInt[],       int inverse[], int idx, int newIdx) {
	readInt[idx] = newIdx;	
	inverse[newIdx] = idx;
}
You need to pay attention to constness. Line ten should read

10 void permutation (int readInt[], int inverse[], int idx, int newIdx);

so that it matches line 84.

Also, you need to #include <climits> for that INT_MAX constant.

Hope this helps.

[edit] Argh... too late again... :-P
Last edited on
appreciate it guys, another one of my glorious noob mistakes!!
Topic archived. No new replies allowed.