On Friday, 23 March 2012 at 15:48:12 UTC, simendsjo wrote:
What's the best way to convert char** from string[]?

This is one way to do it:


import std.algorithm, std.array, std.string, core.stdc.stdio;
void main() {
    auto data = ["red", "yellow", "green"];
    immutable(char)** p = array(map!toStringz(data)).ptr;
    printf("%s %s %s\n", p[0], p[1], p[2]);
}


Note: the pointer array is managed by the D GC.

With DMD 2.059:

immutable(char)** p = data.map!toStringz().array().ptr;

Bye,
bearophile

Reply via email to