# I'm trying to create a function that modifies a 2D array...

This is a discussion on I'm trying to create a function that modifies a 2D array... within the C Programming forums, part of the General Programming Boards category; I'm trying to write a function that inputs an array of 65 elements (ArrA[65]) and a two-dimensional array of Nx65 ...

1. ## I'm trying to create a function that modifies a 2D array...

I'm trying to write a function that inputs an array of 65 elements (ArrA[65]) and a two-dimensional array of Nx65 elements (ArrB[N][65]) and returns the two dimensional array with the one dimensional array appended to the end. I'm keeping track of N in the index ArrB[0][0] (with the rest of the first row full of -1s). I know I'm going to have to malloc/calloc something, but I'm not sure how to prevent the new value from being a local variable. Any ideas?

Would I need to do something like create a temporary array (ArrC) the size of ArrB, then do
Code:
`ArrB = (int*) calloc( (N+1)*65, sizeof(int));`
Then just iterate through assigning all of the values of ArrC to it and assign ArrA at the end?

Sorry, I'm not sure how to make sure ArrB stays a 2D array. Any help is greatly appreciated!

2. define ArrB as an object of type int**, allocate it dynamically, and then assign to it

3. Originally Posted by itCbitC
define ArrB as an object of type int**, allocate it dynamically, and then assign to it
I'm sorry, but I've never used objects. How exactly does this work? I didn't think I could allocate dynamically in C.

Edit: Would it also be possible to just use realloc? I'd only be able to access this as a 1D array, right?

Code:
`ArrB = (int*) realloc (ArrB, (N)*65 * sizeof(int));`
Here is what I have so far (just for debugging):

Code:
```#include <stdio.h>
#include <stdlib.h>#define WIDTH       5
#define loc(r,c)    (((r-1)*WIDTH)+(c-1))
}

int main(){
int CP[5] = {6,7,8,9,10};
int AP[loc(3,5)+1] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};

AP = (int*) realloc(AP, sizeof(AP)+sizeof(CP));
}```
But I am getting the error "error: incompatible types in assignment of `int*' to `int[15]'." What does this mean? I thought I have everything cast correctly.