Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple issue with 2D arrays
    primarykey
    data
    text
    <p>So here is a function in a program that I am working on for class. IN the function, I want to combinations of a 8 character hand for 3,4,5,6,7 and 8 letter words that are validated with a checkDictionary function. Everything works fine and dandy but when I want to store these created words into a 2-d array of chars (basically a 1D array of strings) I get a segmentation fault error. The lines that are apparently causing these issues are the lines such as:</p> <p>strcpy(arrWords[count],letters8); strcpy(arrWords[count],letters7); ...</p> <p>^ until letters3 ^</p> <p>I just want to know what exactly is wrong with me storing into the 2d array with code lines such as those. Also if you could give me any suggestion on how to accurately store these created words into the 2d array (arrWords) it would be greatly appreciated. Thank you so much for your time! :D</p> <p>miscellaneous: </p> <ul> <li><p>this program is basically scrabble</p></li> <li><p>the loops that increment i &amp; j are used to increment through a 2d array board of 10x10 that is filled with "." and placed words by the user.</p></li> </ul> <p>-the dictionary has 40438 actual words</p> <pre><code>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&lt;10; i++) { for (int j=0; j&lt;10; j++) { // if (arrBoard[i][j]!='*') let1=arrBoard[i][j]; for (int a=0; a&lt;8; a++) { let2=computer[a]; for (int b=0; b&lt;8; b++) { let3=computer[b]; char letters3[4]={let1,let2,let3}; cout&lt;&lt;letters3&lt;&lt;endl; if (searchDictionary(dictionary,letters3,40438)==true) strcpy(arrWords[count],letters3); count++; for (int c=0; c&lt;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&lt;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&lt;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&lt;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&lt;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&lt;&lt;"YOURE OVER HERE PAL!"&lt;&lt;endl; // for (int z=0; z&lt;50; z++) // cout&lt;&lt;arrWords[z]&lt;&lt;endl; } } </code></pre> <p>Thank you so much for trying to help!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload