conversion error?

heyya guys.....hoping to get some help here....been getting this error showing up....is there an error in the code?
says invalid conversion from 'char' to 'char (*)(8)'

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

const int MAX = 80;
const int MAXROWS = 10;
const int MAXCOL = 8;

void construct2D (char [][MAXCOL], int, int);
void print2D (const char [][MAXCOL], int, int);
char mapping (int);


int main ()
{
char a, i, j;
int rows, columns;
int max, min;

srand (time(NULL));

for (int i = 1; i <= 3; i++)
{
rows = rand () % 6 + 5;
columns = rand () % 5 + 5;
construct2D ( a, rows, columns);
print2D ( a, rows, columns);
}

}

int k;
const char ALPHANUMERIC [] ={"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"};

char mapping ( int k )
{
char i = ALPHANUMERIC [k];
return i;
}


void construct2D (char a [][MAXCOL], int rows, int columns)
{
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
k = rand () % 61 + 1;
a [i][j] = mapping(k);
}
}
}



void print2D (const char a [][MAXCOL], int rows, int columns)
{
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
cout << " ' " << a [i][j] << " ' " << "\t";
}

cout << endl;
}
}

You are trying to pass type char to a 2-dimensional char array.

a is a char. So make sure you declare a as a 2-dimensional char array or find another way.

After you make a a 2-dimensional array with the 2nd dimension having a size of 8 then you won't have any more errors (tested). If you find another way I wouldn't know.
Last edited on
hey man thanks for the reply.....can i know how to do that? sry.....rly new to this thing...):
So you declared a like char a, i, j;

You should declare it like
char a[sizeHere][MAXCOL], i, j;

You wouldn't do this right?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

void print(int x) // type int
{
    std::cout << x;
}

int main()
{
        double x = 3.141; // type double

        print(x); // 3.141 will turn into 3 because x in print(int x) is int
                  // so you will lose the value 3.141
        return 0;
}

Same concept.
Last edited on
okok....i seem to have got it....trying to fiddle around to fix it now...thanks for the assist!!! will come back if i encounter anything else....
Topic archived. No new replies allowed.