A problem in converting C code

Ali Çehreli acehreli at yahoo.com
Tue Nov 2 22:57:14 UTC 2021


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


More information about the Digitalmars-d-learn mailing list