Help passing array in function

I'm having trouble passing my array into a function. I wrote the program with the desired result then tried to put it into a function,
The program
grabs a string from a file, adds a second string to the first, modifies the combined strings and then outputs to a 2d array. It would be super awesome if someone could point out what I am doing wrong and why with my function headings/prototype. Thank you!

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

#include <iostream>
#include <fstream>
#include <string>

enum cryptionType{ENCRYPTION, DECRYPTION};

void keywordFunction (ifstream& fin, string& encyc,string& word, string alpha, char arrizle[5][5]);

using namespace std;
const int MAX = 25;

int main()
{
    char ch;
    char letter;
    int count = 0;
    int doubleCount = 0;
    int encycLength = 0;
    int k = 0;
    string encyc;
    string word;
    string alpha = "ABCDEFGHIJKLMNOPQRSTUVWXY";
    char arrizle[5][5];
    cryptionType codeType;

    ifstream fin;
    ofstream fout;

    fin.open("mp6encode2.txt");
    fout.open("mp6output.txt");

    if(!fin)
        cout << "Input file did not open.";

keywordFunction (fin,encyc,word,alpha,arrizle);

fin.close();
fin.clear();


return 0;
}
void keywordFunction (ifstream& fin, string& encyc,string& word, string alpha, char arrizle[5][5]);
{
    bool doesMatch = false;

    getline(fin,word);
    word += alpha;
    cout << "word is " << word << endl;
    encyc += word[0];
    for(int counter = 1; counter < word.length(); counter++)
    {
        doesMatch = false;
        for( int j = 0;j < counter - doubleCount; j++)
        {
            if(encyc[j ] == word[counter])
            {
                doesMatch = true;
                doubleCount++;
            }

        }
        if(!doesMatch)
        {
            encyc += word[counter];
            encycLength++;
        }
    }

    cout << "encyc is " << encyc << endl;



    for(int i =0; i <5; i++)
    {
        for(int j=0; j<5; j++)
        {
            arrizle[i][j] = encyc[k++];
        }
    }

    for(int i =0; i <5; i++)
    {
        for(int j=0; j<5; j++)
        {
            cout << arrizle[i][j] << " ";
        }
        cout << endl;
    }



}







Last edited on
I don't know what you mean with 'failed', but on line 44 the ; is wrong and must be removed
Also , you have not initialised some variables in keywordFunction() before using
them .

Are you getting any errors ?
That's probably my problem. The errors i get are that my variables are not declared in this scope. "ifstream, fin, encyc, etc not declared in this scope"
Write your function declaration after this line

using namespace std;

You have also not declared some variables in the second function .
These are local variables , So either you pass them from the main function
or declare them in the second function
Last edited on
Topic archived. No new replies allowed.