A problem in converting C code

pascal111 judas.the.messiah.111 at gmail.com
Tue Nov 2 23:24:56 UTC 2021


On Tuesday, 2 November 2021 at 22:57:14 UTC, Ali Çehreli wrote:
> On 11/2/21 3:36 PM, pascal111 wrote:
>> can we keep the C style of it as it is
>
> As you hint, this really is not D but still... :) I had to make 
> three changes:
>
> import std.stdio;
> // Ali - Importing stdin under a different name
> // to prevent name conflict with std.stdio.stdin;
> import core.stdc.stdio : c_stdin = stdin;
> import core.stdc.string;
>
> int main()
> {
>
>
>   // Ali - Changed the type to char[20]
>   char[20] x;
>
>   // Ali - The last parameter is the stream
>   // to read from.
>   fgets(&x[0],x.sizeof,stdin.getFP());
>
>   x[strcspn(&x[0],"\n")]=0;
>
>   writeln(x);
>
>   if(!strcmp(&x[0],"hello world!"))
>   {
>
>     writeln("yes");
>
>   }
>
>   return 0;
> }
>
> Ali

Yes, exactly, this is literal converting as most possibility.


More information about the Digitalmars-d-learn mailing list