calling fgets()

Mike Wey mike-wey at example.com
Sun Dec 23 08:21:55 PST 2012


On 12/23/2012 02:36 PM, Red wrote:
> How would I call the C library routine fgets() ?
>
> char *fgets(char *s, int size, FILE *stream);
>
> My problem is with the first argument. I am not sure what to declare and
> how to pass it. I tried doing it as you would in C, but it doesn't compile.

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)];

-- 
Mike Wey


More information about the Digitalmars-d-learn mailing list