title: Casting const char * to non const char*
body: <p>I am writing a program in c++ to compare two large XML files and create a file with the identifiers and changes of the products (nodes) that changed. To do so I am using <a href="http://pugixml.org/" rel="nofollow">pugixml</a>.</p>
  
  <p>I am working as a PHP developer at the moment, and it has been a while since I have used c++ so I think I am overlooking something trivial, but after hours of searching online I still have not found the solution to my problem, which is:</p>
  
  <p>The child_value function, which simply gives the value between the tags of an element, returns a const char *. What I am trying to do is put all the values in an array and compare them with the values of all other products (which are in a similar array).</p>
  
  <p>The problem arises when going to the next product, and I need to overwrite the values in the array, which I think is the origin of the segmentation error I am getting. So my question is:</p>
  
  <p>I need to use that const char * for comparisons, but I need to overwrite the values so I can do the next comparison, what is the best way to do this? I have tried strcpy, const_cast (like in the example code below) and loads of other suggestions, but all seem to result
  in the same segmentation error.</p>
  
  <p>It compiles but it will just crash on the second iteration when it tries to overwrite the first values.</p>
  
  <pre><code>for (xml_node groupCurrent = groupsCurrent.child("group");groupCurrent;groupCurrent = groupCurrent.next_sibling("group")){
  
      xml_node productsCurrent = groupCurrent.child("products");
      size_t nrProductsInGroupCurrent = std::distance(productsCurrent.children().begin(), productsCurrent.children().end());
      nrProductsTotalCurrent = nrProductsTotalCurrent + nrProductsInGroupCurrent;
  
      for (xml_node productCurrent = productsCurrent.child("product");productCurrent;productCurrent = productCurrent.next_sibling("product")){
  
          int numberAttributesC=0;
          char * childrenCurrent[32];
  
          for (xml_node attributeCurrent = productCurrent.first_child();attributeCurrent ;attributeCurrent= attributeCurrent.next_sibling()){
              char * nonConstValue = const_cast&lt;char *&gt; (attributeCurrent.child_value());
              childrenCurrent[numberAttributesC]=nonConstValue;
              numberAttributesC++;
          }
  
          /*for(int i = 0;i&lt;numberAttributesC;i++){
              std::cout&lt;&lt;childrenCurrent[i];
          }*/
          //xml_node groupsNew = docNew.child("product_database");
  
      }
  }
  </code></pre>
  
  <p>Any help, suggestions or comments are greatly appreciated. If I find the solution myself in the meanwhile I will post it here.</p>
  
  <p>Regards,
  Anti</p>
  
  <p>PS: On ubuntu using gcc version 4.8.2</p>