need help with char array

trying to print a map but it only prints the first row
1
2
3
4
5
6
7
8
9
10
11
	for(int i=0;i<ymapsize;i++)
	{
		for(int j=0;j<xmapsize;j++)
		{
			mapprinter[j+i*(xmapsize+1)+i]=map[i][j];
			
		}
		mapprinter[(xmapsize+1)*(i+1)]='\n';
	}
	system("cls");
	cout << mapprinter;

any tips would be nice =)
do u want to print map[i][j] or what exactly ?
mapprinter is a 1d char array
which i print out in line 11
but it doesn't print the whole thing only the first row
map[][] is 2d char array where all the variables are being transfered to mapprinter
can u give full explanation for ur problem !
when i run the program only the first row of the map is printed
i want every row to be printed
such as if the map is
00000
00000
00000
00000
00000

then mapprinter only prints
00000
Last edited on
Why not print inside the loop itself?
1
2
3
4
5
6
7
8
for i
{
    for j
    {
        std::cout << map[i][j];
    }
    std::cout << std::endl;
}
(obviously pseudo code)
Last edited on
I'm trying to help but still I don't what the problem is all about
give me the problem maybe I can give u a HINT !
LB its slower

pureevil:
i edited my last comment if you want more tell me
what do u mean by this
mapprinter[(xmapsize+1)*(i+1)]='\n';
to have it
00000\n
00000\n
00000\n
00000\n
00000\n


basicly to have endline for each row
see I don't know what is the main problem
so I've created a code that does what u want
here it is :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# include <iostream>
using namespace std ;
int main ()
{
	int  map [3][3] ;
	for (int i=0 ; i < 3 ;i++)
	{
		for (int j=0 ; j<3 ; j++)
		{
			cin >> map [i][j] ;
		}
	}
	int mapprinter [3] [3] ;


	for(int i=0;i<3;i++)
	{
		for(int j=0;j<3;j++)
		{
			mapprinter[i][j]=map[i][j];
		}
	}

	for (int i=0 ; i<3 ;i++)
	{
		for (int j=0 ; j<3 ;j++)
		{
			cout << mapprinter [i][j] << " " ;
		}
		cout << endl;
	}
	system("Pause");


}

if this is what u don't want...tell me the main problem (not your problem with the mapprinter)
if you do

char mapprinter[12]="0000000000\n"

cout << mapprinter << endl;

the whole thing gets printed
doing the conventional way like you did is 2 times slower

but you can only do this with 1d array with 2d array you get an error which is why i convert the map to a 1d array
but the results where not proper
managed to solve it with some testing

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
	for(int j=0;j<ymapsize;j++)
	{
		for(int i=0;i<xmapsize;i++)
		{
			mapprinter[i+xmapsize*j+j]=map[j][i];
			
		}
	}

	for(int i=1; i<=ymapsize; i++)
	{
		mapprinter[(xmapsize+1)*i-1]=10;
	}


	system("cls");
	cout << mapprinter;
Last edited on
Topic archived. No new replies allowed.