title: Simple C++ char array encryption function - Segment fault
body: <p>As always, problems with the pointers. I am trying to create a very simple "encryption/decryption" function for char arrays. Yes, I know I can use strings, but I want to improve my knowledge about pointers and make use of simple bytes to achieve a simple task.
  So, I created a simple struct like this:</p>
  
  <pre><code>struct text {
      char* value;
      int size;
  }
  </code></pre>
  
  <p>And I created this simple function:</p>
  
  <pre><code>text encrypt(text decrypted) {
      char key = 'X';
      for (int i=0; i&lt;decrypted.size; i++) {
          decrypted.value[i] = decrypted.value[i] ^ (key + i) % 255);
      }
      return decrypted;
  }
  </code></pre>
  
  <p>At this point, an experienced C++ programmer should have spot the problem, I think. Anyway, I call this function like this:</p>
  
  <pre><code>...
  text mytext;
  mytext.value = new char[5];
  mytext.value = "Hello";
  mytext.size = 5;
  
  mytext = encrypt(mytext);
  ...
  </code></pre>
  
  <p>I get, like always, a 'Segmentation fault(core dumped)' error. This is Linux, and, of course, g++. What have I done, again? Thanks!</p>