www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/08/04/07:55:54

To: drodger AT cla320 DOT utsi DOT edu
Subject: Re
From: pfulmek AT email DOT tuwien DOT ac DOT at (Paul FULMEK)
Reply-To: pfulmek AT email DOT tuwien DOT ac DOT at
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
Date: Thu, 4 Aug 1994 09:17:52 +0000

>>>it looks like this
>>>
>>>        double number;
>>>        scanf("1f", &number);
>>>        if (number == 0)
>>>            done = TRUE
>>>
>>>If I use FLOAT in place of DOUBLE  it works fine.  Using DOUBLE the
>>>program won't allow me to exit.  I tried printing out the value of
>>>"number" after I input 0  and the following error occured.

Try the following program; it works fine. You need "%lf" for double,
and "%f" for float arguments. If you compile your program with the
"-v" option the compiler will warn you, if you use a
format-specifier with scanf(), that does not match the
argument-type.

#include <stdio.h>

main()
{
  double dnum=1.0;
  float  fnum=1.0;

  printf("DOUBLE input\n");
  while( dnum != 0.0 )
  { scanf( "%lf", &dnum);
    printf( "DOUBLE %5.2lf\n", dnum );  }
  printf("FLOAT input\n");
  while( fnum != 0.0 )
  { scanf( "%f", &fnum);
    printf( "FLOAT  %5.2f\n", fnum );   }
  return 0;
}

Hope this helps

Paul

--

Technische Universitaet Wien
Institut fuer Werkstoffe der Elektrotechnik
Dipl.-Ing. Paul FULMEK
Tel. (+43 222) 58801/3955
FAX: (+43 222) 50 41 587
Gusshausstrasse 27-29
Austria - 1040 WIEN



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019