c++ help storing '\n' in char array

the problem is that it only shows the first line
i don't thing there is anything wrong with my formula
what i am trying to do is to cout the whole map

1
2
3
4
5
6
7
8
9
for(int i=0; i<20; i++){
for(int j=0; j<20; j++){
mapprinter[i*mapxc+j+i]=map[i][j];
}
mapprinter[(i+1)*mapxc]='\n';
};
system("cls");
cout << mapprinter;
}




yea ... any tips?

How are mapprinter and map declared?
char map [20][20];
is in the main
int mapxc=20;
int mapyc=20;
char mapprinter[520];// only need 420 but just as an insurance
are global

but yea the program doesn't give me an error it's just it only prints the first x row instead of all of the the map.
1
2
3
4
5
6
for (int i = 0; i < mapxc; ++i)
{
    for (int j = 0; j < mapyc; ++j)
        mapprinter[i*(mapxc + 1) + j]=map[i][j];
    mapprinter[i*(mapxc + 1) + mapyc] = '\n';
}

I think
Last edited on
ahh i see i misscalculated all i had to do was swap
mapprinter[(i+1)*mapxc]='\n';
with
mapprinter[i*(mapxc + 1) + mapyc] = '\n';

btw thanks allot =)
Topic archived. No new replies allowed.