On 02/19/2016 07:37 PM, Lisa wrote:

> import std.stdio;
> import std.math;
>
> int main()
> {
>      double a, b, c, p;
>
>      writef("Enter a: ");
>      scanf("%d", &a);

scanf is not a safe function. It trusts the format string and assumes that 'a' really is what the programmer told it. (For example, although 'a' is not an 'int, %d means 'int' and scanf treats it as such.)

The correct format identifier for double is %lf. You need to replace all three of with %lf.

However, you are not writing idiomatic D code. I recommend dropping C functions altogether an taking advantage of readf():

  http://ddili.org/ders/d.en/input.html

Ali

    • Re: 111 Lisa via Digitalmars-d-learn
      • Re: 111 Chris Wright via Digitalmars-d-learn
        • Re: 111 Lisa via Digitalmars-d-learn
          • Re: 111 Chris Wright via Digitalmars-d-learn
            • Re: 111 Adam D. Ruppe via Digitalmars-d-learn
      • Re: 111 cym13 via Digitalmars-d-learn
  • Re: 111 Ivan Kazmenko via Digitalmars-d-learn
  • Re: 111 Ali Çehreli via Digitalmars-d-learn
    • Re: 111 Lisa via Digitalmars-d-learn
    • Re: 111 Lisa via Digitalmars-d-learn
      • Re: 111 Ali Çehreli via Digitalmars-d-learn
        • Re: 111 Lisa via Digitalmars-d-learn
          • Re: 111 Steven Schveighoffer via Digitalmars-d-learn
          • Re: 111 Ivan Kazmenko via Digitalmars-d-learn
            • Re: 111 Lisa via Digitalmars-d-learn
              • Re:... Ivan Kazmenko via Digitalmars-d-learn
              • Re:... Lisa via Digitalmars-d-learn
  • Re: 111 Lisa via Digitalmars-d-learn

Reply via email to