title: Getting the last word from a string
body: <p>In a assignment I need to be able to find the last word from a two dimensional array of strings (the last word for each line/string) so I can apply a cipher to it. I have tried this:</p>
  
  <pre><code>space = strrchr((*array)[i], ' ');                                                 
  if ((name = strstr((*array)[i], search)) != NULL) {
      cipher = 1;
      }
  if (cipher &amp;&amp; name &gt; space) {    
   //Cipher code here
  </code></pre>
  
  <p>Space and Search are defined as:</p>
  
  <pre><code>char *space, *search;
  </code></pre>
  
  <p>*array is a pointer to a two-dimensional array that is declared in main() and I load values into it in a different function.</p>
  
  <p>The code works, but the program crashes after pulling the last word of the first line. While debugging, I get the error: Unhandled exception at 0x009915B0 in Projekt 1.exe: 0xC0000005: Access violation reading location 0xCCCCCCCC. The word from the first line is pulled correctly, and the cipher works (I have tried to print it after each line). </p>
  
  <p>I have tried Googling and consulted other topics on StackOverflow but it didn't help me much. Could anyone point me in the right direction on how to get the last word for each line?</p>
  
  <p>EDIT: I am using the Albam cipher in this case:</p>
  
  <pre><code>for (i = 0; i &lt; lines; i++) {
  
  space = strrchr((*array)[i], ' ');                                                 
  if ((name = strstr((*array)[i], search)) != NULL) {
      cipher = 1;
      }
  
  if (cipher &amp;&amp; name &gt; space) {                                                 
  
      cipher = 1;
      for (j = 0; j &lt; strlen(*array[i]); j++) {
  
          if ((*array)[i][j] &lt; 'Z' &amp;&amp; (*array)[i][j] &gt; 'A' || (*array)[i][j] &lt; 'z' &amp;&amp; (*array)[i][j] &gt; 'a') { 
            if (toupper((*array)[i][j]) &gt; 'A' &amp;&amp; toupper((*array)[i][j]) &lt; 'N')
                (*array)[i][j] = (*array)[i][j] + 13;
            if (toupper((*array)[i][j]) &gt; 'N' &amp;&amp; toupper((*array)[i][j]) &lt; 'Z')
                (*array)[i][j] = (*array)[i][j] - 13;
          }
        }
      }
  }
  </code></pre>