Problem with moving x and 0

Hello i have a problem.I want to make some moving x and 0 for a main menu for a tic tac toe game and it works but i want a x on one side and a 0 on other side now they interlock eachother.I am pretty confused why this is happening.i think the problem might be with printing .Could someone please modify my code and make it work how i wanted to:
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <string>
using namespace std;
#include <windows.h>
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
COORD CursorPos;
void gotoxy_s(int x,int y,string text)
{
    CursorPos.X=x;CursorPos.Y=y;
    SetConsoleCursorPosition(hOut,CursorPos);
    cout<<text;
}
int main()
{
    int len,y;
    string holder="     ";
    string X[]=
    {"     "
    ,"X   X"
    ," X X "
    ,"  X  "
    ," X X "
    ,"X   X"
    ,"     "
    ,"     "
    ,"     "
    };
    string Zero[]=
    {"     "
    ," 000 "
    ,"0   0"
    ,"0   0"
    ,"0   0"
    ," 000 "
    ,"     "
    ,"     "
    ,"     "
    };
    len=9; //this was the problem change it to 8
    do{
        for (y=0;y<len;y++)
		{
			gotoxy_s(3,2+y,X[y]);
		}
        for (y=0;y<len;y++)
		{
			gotoxy_s(11,2+y,Zero[y]);
		}
			holder = X[len];
			for (y=len;y>0;y--)
			{
				X[y]=X[y-1];
			}
			X[0]=holder;
			holder =Zero[0];
			for (y=0;y<len;y++)
            {
				Zero[y]=Zero[y+1];
			}
			Zero[len]=holder;
		Sleep(80);

    }while(true);
    return 0;
}
Last edited on
LInes 49, 52, 58, and 60 access outside the bounds of your arrays.
Ok thanks i fixed it : changed len to 8 instead of 9.
Topic archived. No new replies allowed.