我想要做的是取一个指向的字符串argv[1]并将其复制到另一个数组,但我希望这个新数组是const.
有没有办法将数组声明为const并使用argv[1]同一行的内容初始化它?
我遇到的问题是我无法将其声明为const然后在下一行使用strcpy或某些此类函数复制字符串.那是无效的.
什么是最好的行动方案?
我正在制作一个tic-tac-toe控制台应用程序,我主要完成它.还有一些我要添加的东西,但我遇到了一个大问题.我有一个bool checkwin()函数,它应该看看游戏是否已经赢了,但由于某种原因,无论我的参数是否满足,这个函数总是返回true.这导致程序在第一次移动后结束.为什么这样做,我该如何解决?
bool checkwin( Boardstatus& BSTAT)
{
//Row 'A' checkwin
if (BSTAT.getsquarestatus("A1")==BSTAT.getsquarestatus("A2") && BSTAT.getsquarestatus("A2")==BSTAT.getsquarestatus("A3"))
{
return true;
}
//Row 'B' checkwin
else if (BSTAT.getsquarestatus("B1")==BSTAT.getsquarestatus("B2") && BSTAT.getsquarestatus("B2")==BSTAT.getsquarestatus("B3"))
{
return true;
}
//Row 'C' checkwin
else if (BSTAT.getsquarestatus("C1")==BSTAT.getsquarestatus("C2") && BSTAT.getsquarestatus("C2")==BSTAT.getsquarestatus("C3"))
{
return true;
}
//Column 1 checkwin
else if (BSTAT.getsquarestatus("A1")==BSTAT.getsquarestatus("B1") && BSTAT.getsquarestatus("B1")==BSTAT.getsquarestatus("C1"))
{
return true;
}
//Column 2 checkwin
else if (BSTAT.getsquarestatus("A2")==BSTAT.getsquarestatus("B2") && BSTAT.getsquarestatus("B2")==BSTAT.getsquarestatus("C2"))
{
return true;
}
//Column 3 checkwin
else if (BSTAT.getsquarestatus("A3")==BSTAT.getsquarestatus("B3") && BSTAT.getsquarestatus("B3")==BSTAT.getsquarestatus("C3"))
{
return true;
}
//Diagonal upper-left->bottom-right …Run Code Online (Sandbox Code Playgroud)