Undefined reference

Hello!. I'm a beginner at programming, and I have to make a menu with an Decryption , and a Encryption.I have the code but a I get one error on line 41 undefined reference to 'Decript_Caes()'. I used codeblocks..

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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include <iostream>
# include <cstring>
# include <cstdlib>
# include <conio.h>
# include <stdio.h>
# include <cmath>
# define Decriptare_Caesar '1'
# define Cript_Matrice '2'
# define Iesire '3'

using namespace std;

void Decript_Caes ();
void Cript_Matr ();

int pp_matr(int x) ;

int main()
{
    char r ;
    for(;;)
    {
        system("CLS") ;
        cout << endl ; cout << endl ; cout << endl ; cout << endl ; cout << endl ;
        cout << " 1. Decriptare Caesar. " << endl ;
        cout << " 2. Criptare prin transpozitie cu matrici. " << endl ;
        cout << " 3. Iesire. " << endl ;

        cout << endl ;
        cout << " Optiune: " ;
         system("color 0");
        for(;;)
        {
            r = getch() ;
            if(r==Decriptare_Caesar||r==Cript_Matrice||r==Iesire)
                break;
        }

        if(r==Decriptare_Caesar)
         {
            Decript_Caes() ;
            cout << endl ;
            cout << " Apasati o tasta pentru a reveni la meniu." ;
            getch() ;
        }

        else if(r==Cript_Matrice)
        {
            Cript_Matr() ;
            cout << endl ;
            cout << " Apasati o tasta pentru a reveni la meniu." ;
            getch() ;
        }

        else if(r==Iesire)
            break;
    }
    return 0;
}

void Decript_Caes(char text[100])
{
int i, mar ; char textx[100] ;
mar = strlen(text) ;
for(i=0;i<mar;i++)
if(text[i]==' ') textx[i] = text[i] ;
else
if(((text[i]>'c')&&(text[i]<='z'))||((text[i]>'C')&&(text[i]<='Z'))) textx[i] = text[i] - 3 ;
else
{
if(text[i]=='a') textx[i] = 'x' ;
if(text[i]=='b') textx[i] = 'y' ;
if(text[i]=='c') textx[i] = 'z' ;
if(text[i]=='A') textx[i] = 'X' ;
if(text[i]=='B') textx[i] = 'Y' ;
if(text[i]=='C') textx[i] = 'Z' ;
}
textx[mar] = '\0' ;
cout << endl ;
cout << " Textul decriptat este: "<< textx ;
}


void Cript_Transp()
{
int i, j, mar, nrcol, lit = 0 ;
char text[100] ;
cout << " Introduceti sirul: " ;
cin.getline(text,100) ;
char textx[100], matr[2][50] ;
mar = strlen(text) ;
if(mar%2==0) nrcol = mar/2 ;
else nrcol = mar/2 + 1 ;
for(i=0;i<2;i++)
for(j=0;j<nrcol;j++)
{
if(i==0) matr[i][j] = text[j];
else matr[i][j] = text[i+j+nrcol-1] ;
}
for(j=0;j<nrcol;j++)
for(i=0;i<2;i++)
{
textx[lit] = matr[i][j] ;
lit++;
}
textx[lit] = '\0' ;
cout << endl ;
cout << " Textul criptat este: "<< textx;
}

void Cript_Matr()
{
int mar, marr, i, j, k=0 ;
char textx[100],matr[10][10],matr2[10][10],text[100] ;
cout<<"Introduceti textul: ";
cin.getline(text,100);
mar = strlen(text) ;
if(!pp_matr(mar)) marr = sqrt(mar) + 1 ;
else marr = sqrt(mar) ;
for(i=1;i<=marr;i++)
for(j=1;j<=marr;j++)
{
    matr[i][j] = text[k] ;
k++ ;
}
for(j=1;j<=marr;j++)
for(i=1;i<=marr;i++)
matr2[j][i] = matr[i][j];
k = 0 ;
for(i=1;i<=marr;i++)
for(j=1;j<=marr;j++)
{
textx[k] = matr2[i][j] ;
if(k<mar) k++;
}
textx[k] = '\0' ;
cout << endl ;
cout << " Textul criptat este : " << textx ;
}

int gasit_col_mans(char x, int matr[5][5])
{
int i, j, ok=1, col ;
for(i=0;(i<5)&&ok;i++)
for(j=0;(j<5)&&ok;j++)
if(int(x)==(matr[i][j]+32))
{
ok = 0 ;
col = j ;
}
return col ;
}

int gasit_lin_mans(char x, int matr[5][5])
{
int i, j, ok=1, lin ;
for(i=0;(i<5)&&ok;i++)
for(j=0;(j<5)&&ok;j++)
if(int(x)==(matr[i][j]+32))
{
ok = 0 ;
lin = i ;
}
return lin ;
}

int pp_matr(int x)
{
int i ;
for(i=2;(i<=x);i++)
if((x%i==0)&&((x/i)%i==0)) return 1 ;
return 0 ;
}

Line 13 void Decript_Caes ();
Line 41 Decript_Caes() ;
are consistent. The function takes no parameters.

However, line 61 void Decript_Caes(char text[100])
does not match. Here the function takes a character array as a parameter.

It looks like that last one is what is needed, so lines 13 and 41 should be changed accordingly.
Last edited on
ok. Thanks a lot!
Last edited on
ok so I did that but now I get this error also on line 41 expected primary-expression before 'char'

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
# include <iostream>
# include <cstring>
# include <cstdlib>
# include <conio.h>
# include <stdio.h>
# include <cmath>
# define Decriptare_Caesar '1'
# define Cript_Matrice '2'
# define Iesire '3'

using namespace std;

void Decript_Caes (char text[100]);
void Cript_Matr ();

int pp_matr(int x) ;

int main()
{
    char r ;
    for(;;)
    {
        system("CLS") ;
        cout << endl ; cout << endl ; cout << endl ; cout << endl ; cout << endl ;
        cout << " 1. Decriptare Caesar. " << endl ;
        cout << " 2. Criptare prin transpozitie cu matrici. " << endl ;
        cout << " 3. Iesire. " << endl ;

        cout << endl ;
        cout << " Optiune: " ;
         system("color 0");
        for(;;)
        {
            r = getch() ;
            if(r==Decriptare_Caesar||r==Cript_Matrice||r==Iesire)
                break;
        }

        if(r==Decriptare_Caesar)
         {
            Decript_Caes(char text[100]) ;
            cout << endl ;
            cout << " Apasati o tasta pentru a reveni la meniu." ;
            getch() ;
        }

        else if(r==Cript_Matrice)
        {
            Cript_Matr() ;
            cout << endl ;
            cout << " Apasati o tasta pentru a reveni la meniu." ;
            getch() ;
        }

        else if(r==Iesire)
            break;
    }
    return 0;
}

void Decript_Caes(char text[100])
{
int i, mar ; char textx[100] ;
mar = strlen(text) ;
for(i=0;i<mar;i++)
if(text[i]==' ') textx[i] = text[i] ;
else
if(((text[i]>'c')&&(text[i]<='z'))||((text[i]>'C')&&(text[i]<='Z'))) textx[i] = text[i] - 3 ;
else
{
if(text[i]=='a') textx[i] = 'x' ;
if(text[i]=='b') textx[i] = 'y' ;
if(text[i]=='c') textx[i] = 'z' ;
if(text[i]=='A') textx[i] = 'X' ;
if(text[i]=='B') textx[i] = 'Y' ;
if(text[i]=='C') textx[i] = 'Z' ;
}
textx[mar] = '\0' ;
cout << endl ;
cout << " Textul decriptat este: "<< textx ;
}


void Cript_Matr()
{
int mar, marr, i, j, k=0 ;
char textx[100],matr[10][10],matr2[10][10],text[100] ;
cout<<"Introduceti textul: ";
cin.getline(text,100);
mar = strlen(text) ;
if(!pp_matr(mar)) marr = sqrt(mar) + 1 ;
else marr = sqrt(mar) ;
for(i=1;i<=marr;i++)
for(j=1;j<=marr;j++)
{
    matr[i][j] = text[k] ;
k++ ;
}
for(j=1;j<=marr;j++)
for(i=1;i<=marr;i++)
matr2[j][i] = matr[i][j];
k = 0 ;
for(i=1;i<=marr;i++)
for(j=1;j<=marr;j++)
{
textx[k] = matr2[i][j] ;
if(k<mar) k++;
}
textx[k] = '\0' ;
cout << endl ;
cout << " Textul criptat este : " << textx ;
}


int pp_matr(int x)
{
int i ;
for(i=2;(i<=x);i++)
if((x%i==0)&&((x/i)%i==0)) return 1 ;
return 0 ;
}
Well, since the function is supposed to decrypt the text, the question arises, "what text?". You are now trying to pass it a new uninitialised array. Most likely what you want is to have the array already existing. Perhaps declare it around line 20 or 21:
 
    char text[100];

Then the function call at line 41 becomes simply
 
    Decript_Caes(text);


But that isn't enough. The code will now probably compile, but it won't do anything useful. That's because the array text is uninitialised. So before calling the decrypt function, you need to fill that array with some sort of input. You may want to add another function to get the user to enter the text.
I did some change but I still get one error \main.cpp|61|error: expected unqualified-id before '1'|.
And about the text I have to type it from keybord.

PS The Decryption is Caesar and the Encryption is Matrices
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
# include <iostream>
# include <string>
# include <cstdlib>
# include <conio.h>
# include <stdio.h>
# include <cmath>
# define Decriptare_Caesar '1'
# define Cript_Matrice '2'
# define Iesire '3'

using namespace std;

void Decript_Caes();
void Cript_Matr ();

int pp_matr(int x) ;

int main()
{
    char r ;
    for(;;)
    {
        system("CLS") ;
        cout << endl ; cout << endl ; cout << endl ; cout << endl ; cout << endl ;
        cout << " 1. Decriptare Caesar. " << endl ;
        cout << " 2. Criptare prin transpozitie cu matrici. " << endl ;
        cout << " 3. Iesire. " << endl ;

        cout << endl ;
        cout << " Optiune: " ;
         system("color 0");
        for(;;)
        {
            r = getch() ;
            if(r==Decriptare_Caesar||r==Cript_Matrice||r==Iesire)
                break;
        }

        if(r==Decriptare_Caesar)
         {
            Decript_Caes() ;
            cout << endl ;
            cout << " Apasati o tasta pentru a reveni la meniu." ;
            getch() ;
        }

        else if(r==Cript_Matrice)
        {
            Cript_Matr() ;
            cout << endl ;
            cout << " Apasati o tasta pentru a reveni la meniu." ;
            getch() ;
        }

        else if(r==Iesire)
            break;
    }
    return 0;
}

void Decriptare_Caesar(char text[100]){
    int i, mar ;
    char textx[100] ;
    mar = strlen(text) ;
    for(i=0;i<mar;i++)
        if(text[i]==' ') textx[i] = text[i] ;
        else
			if(((text[i]>='a')&&(text[i]<='w'))||((text[i]>='A')&&(text[i]<='W')))
				textx[i] = text[i] + 3 ;
            else{
                if(text[i]=='x') textx[i] = 'a' ;
                if(text[i]=='y') textx[i] = 'b' ;
                if(text[i]=='z') textx[i] = 'c' ;
                if(text[i]=='X') textx[i] = 'A' ;
                if(text[i]=='Y') textx[i] = 'B' ;
                if(text[i]=='Z') textx[i] = 'C' ;
            }
    textx[mar] = '\0' ;
	cout << "Textul criptat este: "<< textx <<endl<<endl;
}



void Cript_Matr()
{
int mar, marr, i, j, k=0 ;
char textx[100],matr[10][10],matr2[10][10],text[100] ;
cout<<"Introduceti textul: ";
cin.getline(text,100);
mar = strlen(text) ;
if(!pp_matr(mar)) marr = sqrt(mar) + 1 ;
else marr = sqrt(mar) ;
for(i=1;i<=marr;i++)
for(j=1;j<=marr;j++)
{
    matr[i][j] = text[k] ;
k++ ;
}
for(j=1;j<=marr;j++)
for(i=1;i<=marr;i++)
matr2[j][i] = matr[i][j];
k = 0 ;
for(i=1;i<=marr;i++)
for(j=1;j<=marr;j++)
{
textx[k] = matr2[i][j] ;
if(k<mar) k++;
}
textx[k] = '\0' ;
cout << endl ;
cout << " Textul criptat este : " << textx ;
}


int pp_matr(int x)
{
int i ;
for(i=2;(i<=x);i++)
if((x%i==0)&&((x/i)%i==0)) return 1 ;
return 0 ;
}
Last edited on
Given: # define Decriptare_Caesar '1'

void Decriptare_Caesar(char text[100]){
becomes:
void '1'(char text[100]){

Look good to you? Avoid the use of macros where possible in C++.
I try that but nothing change!
I try that but nothing change!

You tried what? There was no course of action given, only a description of what was happening.
I try that but nothing change!

You tried what? There was no course of action given, only a description of what was happening.

I tried to change
void Decriptare_Caesar(char text[100]){
to
void '1'(char text[100]){
What Cire is saying is to provide your new code.
Sorry I didn't understand what he means
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
# include <iostream>
# include <string>
# include <cstdlib>
# include <conio.h>
# include <stdio.h>
# include <cmath>
# define Decriptare_Caesar '1'
# define Cript_Matrice '2'
# define Iesire '3'

using namespace std;

void Decript_Caes();
void Cript_Matr ();

int pp_matr(int x) ;

int main()
{
    char r ;
    for(;;)
    {
        system("CLS") ;
        cout << endl ; cout << endl ; cout << endl ; cout << endl ; cout << endl ;
        cout << " 1. Decriptare Caesar. " << endl ;
        cout << " 2. Criptare prin transpozitie cu matrici. " << endl ;
        cout << " 3. Iesire. " << endl ;

        cout << endl ;
        cout << " Optiune: " ;
         system("color 0");
        for(;;)
        {
            r = getch() ;
            if(r==Decriptare_Caesar||r==Cript_Matrice||r==Iesire)
                break;
        }

        if(r==Decriptare_Caesar)
         {
            Decript_Caes() ;
            cout << endl ;
            cout << " Apasati o tasta pentru a reveni la meniu." ;
            getch() ;
        }

        else if(r==Cript_Matrice)
        {
            Cript_Matr() ;
            cout << endl ;
            cout << " Apasati o tasta pentru a reveni la meniu." ;
            getch() ;
        }

        else if(r==Iesire)
            break;
    }
    return 0;
}

 void '1'(char text[100]){
    int i, mar ;
    char textx[100] ;
    mar = strlen(text) ;
    for(i=0;i<mar;i++)
        if(text[i]==' ') textx[i] = text[i] ;
        else
			if(((text[i]>='a')&&(text[i]<='w'))||((text[i]>='A')&&(text[i]<='W')))
				textx[i] = text[i] + 3 ;
            else{
                if(text[i]=='x') textx[i] = 'a' ;
                if(text[i]=='y') textx[i] = 'b' ;
                if(text[i]=='z') textx[i] = 'c' ;
                if(text[i]=='X') textx[i] = 'A' ;
                if(text[i]=='Y') textx[i] = 'B' ;
                if(text[i]=='Z') textx[i] = 'C' ;
            }
    textx[mar] = '\0' ;
	cout << "Textul criptat este: "<< textx <<endl<<endl;
}



void Cript_Matr()
{
int mar, marr, i, j, k=0 ;
char textx[100],matr[10][10],matr2[10][10],text[100] ;
cout<<"Introduceti textul: ";
cin.getline(text,100);
mar = strlen(text) ;
if(!pp_matr(mar)) marr = sqrt(mar) + 1 ;
else marr = sqrt(mar) ;
for(i=1;i<=marr;i++)
for(j=1;j<=marr;j++)
{
    matr[i][j] = text[k] ;
k++ ;
}
for(j=1;j<=marr;j++)
for(i=1;i<=marr;i++)
matr2[j][i] = matr[i][j];
k = 0 ;
for(i=1;i<=marr;i++)
for(j=1;j<=marr;j++)
{
textx[k] = matr2[i][j] ;
if(k<mar) k++;
}
textx[k] = '\0' ;
cout << endl ;
cout << " Textul criptat este : " << textx ;
}


int pp_matr(int x)
{
int i ;
for(i=2;(i<=x);i++)
if((x%i==0)&&((x/i)%i==0)) return 1 ;
return 0 ;
}
I tried to change
void Decriptare_Caesar(char text[100]){
to
void '1'(char text[100]){


And that didn't change anything because, as I pointed out, your macro was already doing that. You cannot have a function named '1'.
Topic archived. No new replies allowed.