title: C: Initialize a constant string array dynamically
body: <p>I know the problem seems weird but I need to initialize (or convert) a constant string array in C.</p>
  
  <p>The problem is that the string array is initialized dynamically but an API function I'd like to use only accepts constant string arrays.</p>
  
  <p>I know that this works:</p>
  
  <pre><code>const char *const arr[] = { "test" };
  </code></pre>
  
  <p>But again: Since I don't know how many items the array will have nor I know the content pre runtime, I can't initialize the array that way.</p>
  
  <p>So of course this won't work</p>
  
  <pre><code>const char *const arr[1]; 
  arr[1] = "test"; // won't work
  </code></pre>
  
  <p>My question is: Is it possible to convert somehow the dynamically string array to a read-only one? Or is there a way to initialize the array dynamically once?</p>
  
  <p>EDIT 1: My exact problem</p>
  
  <pre><code>int len = 8;
  const char *names1[8] = {"test0","test1","test2","test3","test4","test5","test6","test7" }; // not what I'm looking for
  const char *names2[len]; 
  const char *names3[len];
  
  // nearly what I'm looking for
  for(int j=0; j&lt;len; j++) {
      names2[j] = "test";
  }
  
  // exactly what I'm looking for
  for(int j=0; j&lt;len; j++) {
      sprintf(names3[j],"%s%d","test",j); // discards 'const' qualifier
  }
  
  // ...
  
  Cudd_DumpDot(gbm, 1, ddnodearray, names1, NULL, outfile);
  Cudd_DumpDot(gbm, 1, ddnodearray, names2, NULL, outfile);
  Cudd_DumpDot(gbm, 1, ddnodearray, names3, NULL, outfile); // won't work
  </code></pre>
  
  <p>Okay this is my progress so far.
  The method with <code>names2</code> is indeed working but I'd like to use <code>sprintf</code> (as shown with <code>names3</code>) since I need to append <code>j</code> in this case. And this would wound the <code>const</code> qualifier.</p>