Homework help please??

Hey guys (and gals),

I'm running into some trouble on a homework assignment of mine. When I try and build my program (I'm in visual studio 2010), I get two errors:

error C2664: 'readPuzzle' cannot convert parameter 2 from 'char[20][20]' to 'char'
error C2660: 'printPuzzle': function does not take 3 arguments.

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
#include <fstream>
#include <iomanip>
#include <iostream>
using namespace std;

const int MAX_ROWS = 20;
const int MAX_COLUMNS = 20;
const int MAX_WORD_COUNT = 25;
const int MAX_WORD_LENGTH = 32;
const string FILE_NAME = "puzzle.txt";

void readPuzzle (ifstream, char, int &, int &);
void printPuzzle (char);

int main ()
{
	ifstream inputFile;
	char puzzleArray[MAX_ROWS][MAX_COLUMNS];
	int Rows = 0;
	int Columns = 0;

	readPuzzle (inputFile, puzzleArray, Rows, Columns);
	printPuzzle (Rows, Columns, puzzleArray);
}

void readPuzzle (ifstream inputFile, char puzzleArray [][MAX_COLUMNS],
				 int &Rows, int &Columns)
{
	inputFile.open(FILE_NAME);
	if (inputFile.fail())
	{
		cout << "Error: failure to open file." << endl;
	}

	inputFile >> Rows;
	inputFile >> Columns;

	inputFile.peek();
	while (!inputFile.eof())
	{
		for (int i = 0; i < MAX_ROWS; i++)
		{
			for (int j = 0; j < MAX_COLUMNS; j++)
			{
				inputFile >> puzzleArray[i][j];
			}
		}
	}
}

void printPuzzle (int Rows, int Columns, char puzzleArray[][MAX_COLUMNS])
{
	cout << "***************************\n";
	cout << "*       Find A Word       *\n";
	cout << "***************************\n\n";

	cout << "Number of Rows: " << Rows << endl;
	cout << "Number of Columns: " << Columns << endl << endl;

	cout << "Puzzle\n";
	cout << "------\n\n";

	for (int i = 0; i < Rows; i++)
	{
		for (int j = 0; j < Columns; j++)
		{
			cout << puzzleArray[i][j];
		}
		cout << endl;
	}
}


My programming skills are a bit rusty since I took my first course 2 years ago, so am I missing something completely obvious? I've tried quite a few things and I'm completely blanking. Also if anyone sees anything glaringly obvious with my program, please let me know! Even if I can get hints I'll be happy!

Thank you!
@blazer52

error C2664: 'readPuzzle' cannot convert parameter 2 from 'char[20][20]' to 'char'

I'll let someone more knowledgeable about passing arrays, handle this one..

error C2660: 'printPuzzle': function does not take 3 arguments.

You declare void printPuzzle (char);, but in your program, you try calling it with printPuzzle (Rows, Columns, puzzleArray);
Oh wow I totally missed that, thanks! Like I said I'm rusty and I'm missing the dumbest little things.

Now about this array passing situation...
Alright I've moved on a bit seeing as I can probably come back to the array passing, and I've moved into two more errors. I have to pass some words into an array of structs, and when I'm trying to call the arrays the programs not recognizing them for some reason.

Here's what I have:

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
#include <fstream>
#include <iomanip>
#include <iostream>
using namespace std;

const int MAX_ROWS = 20;
const int MAX_COLUMNS = 20;
const int MAX_WORD_COUNT = 25;
const int MAX_WORD_LENGTH = 32;
const string FILE_NAME = "puzzle.txt";

struct Word
{
	char mWords[MAX_WORD_COUNT];
	int mRowFound;
	int mColumnFound;
	bool mbIsFound;
};

void readPuzzle (ifstream, char, int &, int &);
void printPuzzle (int, int, char);
void readWords (ifstream, Word);
void printWords (const Word);

int main ()
{
	ifstream inputFile;
	char puzzleArray[MAX_ROWS][MAX_COLUMNS];
	int Rows = 0;
	int Columns = 0;

	readPuzzle (inputFile, puzzleArray, Rows, Columns);
	printPuzzle (Rows, Columns, puzzleArray);
}

void readPuzzle (ifstream inputFile, char puzzleArray [][MAX_COLUMNS],
				 int &Rows, int &Columns)
{
	inputFile.open(FILE_NAME);
	if (inputFile.fail())
	{
		cout << "Error: failure to open file." << endl;
	}

	inputFile >> Rows;
	inputFile >> Columns;

	inputFile.peek();
	while (!inputFile.eof())
	{
		for (int i = 0; i < MAX_ROWS; i++)
		{
			for (int j = 0; j < MAX_COLUMNS; j++)
			{
				inputFile >> puzzleArray[i][j];
			}
		}
	}
}

void printPuzzle (int Rows, int Columns, char puzzleArray[][MAX_COLUMNS])
{
	cout << "***************************\n";
	cout << "*       Find A Word       *\n";
	cout << "***************************\n\n";

	cout << "Number of Rows: " << Rows << endl;
	cout << "Number of Columns: " << Columns << endl << endl;

	cout << "Puzzle\n";
	cout << "------\n\n";

	for (int i = 0; i < Rows; i++)
	{
		for (int j = 0; j < Columns; j++)
		{
			cout << puzzleArray[i][j];
		}
		cout << endl;
	}
}

void readWords (ifstream inputFile, Word sWords[])
{
	int counter = 0;

	inputFile.peek();
	while (!inputFile.eof() && counter < MAX_WORD_COUNT)
	{
		inputFile.getline(sWords.mWords[counter], MAX_WORD_LENGTH);
		inputFile.get();
		counter++;
	}
}

void printWords (const Word sWords[])
{
	cout << "\nWords\n";
	cout << "-----\n\n";

	for (int i = 0; i < MAX_WORD_COUNT; i++)
	{
		cout << sWords.mWords[i];
		cout << endl;
	}
}


The other three members in the struct don't need to be used until the last part of the assignment, so don't mind them.
Topic archived. No new replies allowed.