How to handle char* to string from C functions?

John Colvin john.loughran.colvin at gmail.com
Wed Jan 1 15:59:05 PST 2014


On Wednesday, 1 January 2014 at 23:03:06 UTC, Gary Willoughby 
wrote:
> I'm calling an external C function which returns a string 
> delivered via a char*. When i print this string out, like this:
>
> char* result = func();
>
> writefln("String: %s", *result);
>
> I only get one character printed.

You're not asking to print the string, by dereferencing the 
pointer you're literally asking to print the first character.

If you don't want to have to walk the length of the the string to 
make the D array equivalent, you could always wrap it in a 
forward range to emulate c string handling.


More information about the Digitalmars-d-learn mailing list