だから、ここに私がクラスのために取り組んでいるプログラムの関数があります。関数では、checkDictionary 関数で検証される 3、4、5、6、7 および 8 文字の単語の 8 文字の手の組み合わせが必要です。すべてがうまく機能しますが、これらの作成された単語を文字の 2 次元配列 (基本的には文字列の 1 次元配列) に格納しようとすると、セグメンテーション違反エラーが発生します。これらの問題を明らかに引き起こしている行は、次のような行です。
strcpy(arrWords[count],letters8); strcpy(arrWords[count],letters7); ...
^ 文字まで 3 ^
そのようなコード行を使用して 2 次元配列に格納することの正確な問題を知りたいだけです。また、これらの作成された単語を 2 次元配列 (arrWords) に正確に格納する方法について何か提案をいただければ幸いです。お時間をいただきありがとうございました!:D
その他:
このプログラムは基本的にスクラブルです
i & j をインクリメントするループは、「.」で埋められた 10x10 の 2D アレイ ボードをインクリメントするために使用されます。ユーザーが言葉を配置します。
-辞書には40438の実際の単語があります
void computerMove(char dictionary[][45], char arrBoard[11][11], char computer[9])
{
char let1, let2, let3, let4, let5, let6, let7, let8;
// char letters3[4];
// char letters4[5];
// char letters5[6];
// char letters6[7];
// char letters7[8];
// char letters8[9];
int count = 0;
char arrWords[40438][10];
for (int i=0; i<10; i++)
{
for (int j=0; j<10; j++)
{
// if (arrBoard[i][j]!='*')
let1=arrBoard[i][j];
for (int a=0; a<8; a++)
{
let2=computer[a];
for (int b=0; b<8; b++)
{
let3=computer[b];
char letters3[4]={let1,let2,let3};
cout<<letters3<<endl;
if (searchDictionary(dictionary,letters3,40438)==true)
strcpy(arrWords[count],letters3);
count++;
for (int c=0; c<8; c++)
{
let4=computer[c];
char letters4[5]={let1,let2,let3,let4};
if (searchDictionary(dictionary,letters4,40438)==true)
strcpy(arrWords[count],letters4);
count++;
for (int d=0; d<8; d++)
{
let5=computer[d];
char letters5[6]={let1,let2,let3,let4,let5};
if (searchDictionary(dictionary,letters5,40438)==true)
strcpy(arrWords[count],letters5);
count++;
for (int e=0; e<8; e++)
{
let6=computer[e];
char letters6[7]={let1,let2,let3,let4,let5,let6};
if (searchDictionary(dictionary,letters6,40438)==true)
strcpy(arrWords[count],letters6);
count++;
for (int f=0; f<8; f++)
{
let7=computer[f];
char letters7[8]={let1,let2,let3,let4,let5,let6,let7};
if (searchDictionary(dictionary,letters7,40438)==true)
strcpy(arrWords[count],letters7);
count++;
for (int g=0; g<8; g++)
{
let8=computer[g];
char letters8[9]={let1,let2,let3,let4,let5,let6,let7,let8};
if (searchDictionary(dictionary,letters8,40438)==true)
strcpy(arrWords[count],letters8);
count++;
}
}
}
}
}
}
}
}
// cout<<"YOURE OVER HERE PAL!"<<endl;
// for (int z=0; z<50; z++)
// cout<<arrWords[z]<<endl;
}
}
助けてくれてどうもありがとう!