Can I output strings using core.stdc.stdio?
Godnyx
rempas at tutanota.com
Wed Dec 23 19:02:23 UTC 2020
On Wednesday, 23 December 2020 at 13:06:37 UTC, drug wrote:
> On 12/23/20 3:23 PM, Godnyx wrote:
>>
>> Any ideas?
>
> Just fix your typos:
>
> ```D
> import std : printf, toStringz;
>
> void put(A...)(string prompt, A args) {
> static foreach (ulong i; 0..args.length) {
> static if (is(typeof(args[i]) == string))
> printf("%s\n", args[i].toStringz);
> static if (is(typeof(args[i]) == int))
> printf("%i\n", args[i]);
> static if (is(typeof(args[i]) == bool)) {
> if (args[i])
> printf("true");
> else
> printf("false");
> }
> }
> }
>
> void main() {
> put("Prompt:", "Hello, my age is: ", 19, true);
> }
> ```
>
> P.S. replace `arg` by `args[i]`
Damn I'm fucking BLIND! Anyway I changed it to foreach (x; args)
to get the args itself. Thanks for anything man! The community is
the best thing about D!!! ;)
More information about the Digitalmars-d-learn
mailing list