Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Does your words file actually have <code>5049</code> entries? Even if it doesn't, you shouldn't assume that it does. Your <code>readFile</code> function should determine how many words are <em>actually</em> present in your <code>words</code> array after reading the file, otherwise, taking a random index into the <code>words</code> array will result in accessing uninitialized strings, which I suspect is leading to your memory corruption.</p> <p>So, if <code>readFile</code> only sees <em>10</em> words, you should only be choosing a random word between indices <code>0..9</code>. You're already keeping the number of words in variable <code>z</code> in the <code>readFile</code> method, share that with the rest of your code.</p> <p>When you choose a random index into an array, note that since the arrays are 0-based, you should get the random and just mod by the number of valid array elements. So use <code>int randomNum = rand() % 5049;</code> without the <code>+1</code>.</p> <p>Furthermore, all this <code>strlen/+1/-1</code> stuff is unnecessary and confusing, prefer <code>strncpy</code> over <code>memcpy</code> (and <code>strcpy</code>) for strings and you don't need to deal with that. Note that the result of<code>strlen</code> <strong>doesn't</strong> include the null terminator, so you won't need to account for that with <code>-1</code>. I think that your <code>jumbleWord</code> function should always be ignoring the last <code>char</code> in the jumble.</p> <p>Use this strategy for your string allocations: you have <code>MAX_WORD_LENGTH</code>, declare strings in your game as either <code>char word[MAX_WORD_LENGTH + 1]</code> or <code>char *word = malloc(MAX_WORD_LENGTH + 1)</code>. Now to copy strings, use <code>strncpy(src, dest, MAX_WORD_LENGTH)</code>.</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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