I'm writing a simple game in C. So I'm trying to save some data to a 2dim array which I malloc'd correctly. The problem is though when I want to pass that variable I wrote to, to another function.
int readMap(FILE *eingabe, map_t *map, config_t *configstruct, pacman_t *pacman)
{
int i = 0, j = 0, k = 0, pac = 0;
map->mapdesign = (char**) malloc(sizeof(char*) * map->height);
do
{
for (i = 0; i < map->height; i++)
{
map->mapdesign[i] = (char*) malloc(sizeof(char) * (map->width + 1));
for (j = 0; j < map->width; j++)
{
fscanf(eingabe, "%c", &map->mapdesign[i][j]);
printf("%c", map->mapdesign[i][j]);
if (map->mapdesign[i][j] == configstruct->ghost)
map->ghostcount++;
else if (map->mapdesign[i][j] == configstruct->foodtypes[0]
|| map->mapdesign[i][j] == configstruct->foodtypes[1])
{
map->foodcount++;
}
for (k = 0; k < PAC; k++)
{
if (map->mapdesign[i][j] == configstruct->pacman[k])
{
pacman->cordinate.x = j;
pacman->cordinate.y = i;
if (pac > 1)
return -1;
pac++;
}
k++;
}
}
}
} while (!feof(eingabe));
return 0;
}
When I use that printf in the function itself it prints out what I want. Then I decided that I want to use a function that prints that out for me which looks like that:
int renderMap(map_t *mapstr)
{
int i = 0;
clrscr();
for (i = 0; i < mapstr->height; i++)
puts(mapstr->mapdesign[i]);
return 0;
}
This function above should print out that:
But it actually prints this:
Thanks in advance!