calling fgets()

Red resmith at lavabit.com
Mon Dec 24 04:00:05 PST 2012


On Sunday, 23 December 2012 at 16:20:47 UTC, Mike Wey wrote:

>
> If you declare an char array you could pass it's pointer and 
> length as the first two arguments.
>
> char[] buff = new char[1024];
> fgets(buff.ptr, buff.length, someStream);
> buff = buff[0 .. strlen(buff)];

Thanks, that does work (buff.length has to be cast to an int). 
Which is surprising. I would have thought that a char[] in D 
would not equate to a char array in C since the D char's are 
UTF-8,  and that a byte[] would have to be used (byte[] also 
works with a cast).


More information about the Digitalmars-d-learn mailing list