I am trying to assign values to a 2d int array in C.
int **worldMap;
I want to assign each row to the array, so I do this in a loop:
worldMap[0][sprCount] = split(tmp.c_str(), delim);
sprCount++;
The problem is I get an error the above line saying can not convert int* to int.
Here is the code to create the 2D array:
int** Array2D(int arraySizeX, int arraySizeY)
{
int** theArray;
theArray = (int**) malloc(arraySizeX*sizeof(int*));
for (int i = 0; i < arraySizeX; i++)
theArray[i] = (int*) malloc(arraySizeY*sizeof(int));
return theArray;
}
I want to take the return pointer of this function (shown above) and put it into the Y dimension.
int* split(const char* str, const char* delim)
{
char* tok;
int* result;
int count = 0;
tok = strtok((char*)str, delim);
while (tok != NULL)
{
count++;
tok = strtok(NULL, delim);
}
result = (int*)malloc(sizeof(int) * count);
count = 0;
tok = strtok((char*)str, delim);
while (tok != NULL)
{
result[count] = atoi(tok);
count++;
tok = strtok(NULL, delim);
}
return result;
}