getting a 2d array with pointer

I'm new to using pointers and I have a problem. I must get a 2D array of characters from the user and the user is giving me the number of rows and columns and what the array should be filled with.

I wrote the code below for it but it doesn't work.I tried searching for such thing but I didn't find anything. can you help me to fix the error with this code please?
1
2
3
4
5
6
7
8
9
10
11
12
     int rows,col,i,j;
    char **array;
    int *storage;
    cin >> rows >> col;
    array = new *int[rows];
    storage = new int[rows*col];
    for (int i = 0; i < rows; ++i)
        array[i] = storage + col * i;
    for(i=0;i<rows;i++){
        for(j=0;j<col;j++){
            cin>>array[i][j];}
    }
Last edited on
I must get a 2D array of characters from the user

Then why do you have int at lines 3, 5 and 6?

Line 5 has the asterisk misplaced. It should be
 
    array = new int*[rows];

(but the int should really be char).
Topic archived. No new replies allowed.