473,854 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem: scanf used for double

Please see the following code:

/* main.c */

#include <stdio.h>

int main()
{
double d;
scanf("%f", &d);
printf("%g\n", d);
}

The problem is, whatever I input to stdin (even an illegal data), the
program just print a number that seems to be a data from "raw memory",
ie uninitialized memory (for example: "5.35162e-315").

And if I replace the statement "double d" with "double d = 3.14", then
I'll always get the output "3.14" for whatever I input (even an
illegal data).

Then I may get the conclusion that the "scanf" statement never does
its job. And I have tried this under 3 compilers and none of them give
the right result.

Please give me some explanation about this.

Thanks.
Nov 13 '05
16 46750
Irrwahn Grausewitz <ir*******@free net.de> spoke thus:
Nope, according to ISO/IEC 9899:1999 5.1.2.2.3 and 7.20.4.3#5
it is perfectly portable.


<dumb>So if 0 is portable, why the EXIT_SUCCESS macro?</dumb>

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Nov 13 '05 #11
Christopher Benson-Manica <at***@nospam.c yberspace.org> wrote:
Irrwahn Grausewitz <ir*******@free net.de> spoke thus:
Nope, according to ISO/IEC 9899:1999 5.1.2.2.3 and 7.20.4.3#5
it is perfectly portable.


<dumb>So if 0 is portable, why the EXIT_SUCCESS macro?</dumb>


Because it's more descriptive and has a portable(!) and descriptive
counter-part, EXIT_FAILURE.

ISO/IEC 9899:1999 7.20.4.3
5 [...] If the value of status is zero or EXIT_SUCCESS, an
implementation-defined form of the status successful termination is
returned. If the value of status is EXIT_FAILURE, an implementation-
defined form of the status unsuccessful termination is returned.
Otherwise the status returned is implementation-defined.

Regards
--
Irrwahn
(ir*******@free net.de)
Nov 13 '05 #12
Irrwahn Grausewitz <ir*******@free net.de> spoke thus:
Because it's more descriptive and has a portable(!) and descriptive
counter-part, EXIT_FAILURE.


So it's kind of like the unary + thing, symmetry and all? I dunno, I always
thought the l337-ness of C code was directly related to how obfuscated it
looked ;)

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Nov 13 '05 #13
Christopher Benson-Manica <at***@nospam.c yberspace.org> wrote:
Irrwahn Grausewitz <ir*******@free net.de> spoke thus:
Because it's more descriptive and has a portable(!) and descriptive
counter-part, EXIT_FAILURE.
So it's kind of like the unary + thing, symmetry and all?


Hm, well, yes and no. I can remember a discussion about this in c.l.c
or c.s.c, where the claim was made that in the context of program exit
codes 0 may describe a kind of successful termination different from
what EXIT_SUCCESS results in. Whatever that means, practically.
I dunno, I always
thought the l337-ness of C code was directly related to how obfuscated it
looked ;)


:)

Regards
--
Irrwahn
(ir*******@free net.de)
Nov 13 '05 #14
In <bm**********@c hessie.cirr.com > Christopher Benson-Manica <at***@nospam.c yberspace.org> writes:
Irrwahn Grausewitz <ir*******@free net.de> spoke thus:
Because it's more descriptive and has a portable(!) and descriptive
counter-part, EXIT_FAILURE.


So it's kind of like the unary + thing, symmetry and all?


Exactly.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #15
In <gb************ *************** *****@4ax.com> Irrwahn Grausewitz <ir*******@free net.de> writes:
Christopher Benson-Manica <at***@nospam.c yberspace.org> wrote:
Irrwahn Grausewitz <ir*******@free net.de> spoke thus:
Because it's more descriptive and has a portable(!) and descriptive
counter-part, EXIT_FAILURE.


So it's kind of like the unary + thing, symmetry and all?


Hm, well, yes and no. I can remember a discussion about this in c.l.c
or c.s.c, where the claim was made that in the context of program exit
codes 0 may describe a kind of successful termination different from
what EXIT_SUCCESS results in. Whatever that means, practically.


Nothing at all, in the context of portable programming. Furthermore, the
most natural interpretation of the standard is that both are mapped to
the *same* form of successful termination.

5 Finally, control is returned to the host environment. If the
value of status is zero or EXIT_SUCCESS, an implementation-defined
^^
form of the status successful termination is returned.

The standard talks about a *single* "implementa tion-defined form of
the status successful termination".

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #16
Da*****@cern.ch (Dan Pop) wrote:
In <gb************ *************** *****@4ax.com> Irrwahn Grausewitz <ir*******@free net.de> writes:


<snip>
Hm, well, yes and no. I can remember a discussion about this in c.l.c
or c.s.c, where the claim was made that in the context of program exit
codes 0 may describe a kind of successful termination different from
what EXIT_SUCCESS results in. Whatever that means, practically.


Nothing at all, in the context of portable programming. Furthermore, the
most natural interpretation of the standard is that both are mapped to
the *same* form of successful termination.

5 Finally, control is returned to the host environment. If the
value of status is zero or EXIT_SUCCESS, an implementation-defined
^^
form of the status successful termination is returned.

The standard talks about a *single* "implementa tion-defined form of
the status successful termination".


It's the most natural interpretation, I agree. I just remembered the
discussion, not the outcome...

--
Irrwahn
(ir*******@free net.de)
Nov 13 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6212
by: Julián Albo | last post by:
Hello. This test: #include <stdio.h> int main () { double a= -1.0e-120; if (a < 0.0)
0
1459
by: Severino | last post by:
Hi all, we have developed a .NET component for use inside Windows Forms: this component has been written using VC++.NET (2003) and is working perfectly when inserted inside VC#.NET or VB.NET projects; its generated assembly is inside MyAssembly.dll When used inside a VC++.NET project it appears correctly over forms at design time but when trying to compile the project we get the following error:
11
3526
by: Vinod | last post by:
Hi, I am working in the project where VC6 code is ported to VC8 (VC++ .Net 2005) I got a problem when I cast a double value to unsigned int. Problem is I couldn’t get the proper value after casting (explicitly / implicitly). Code looks as below : const double d_a = 100e-9; // 100ns const double d_b = 20e-9; // 20ns
3
1672
by: Tomasz Bednarz | last post by:
Can someone help me to parse double precision numbers from text file? I have a sample text file which is as follows: VARIABLES = x, y ZONE I=11, J=11 1.10000000000 0.10000000000 0.10000000000 0.20000000000 0.20000000000 0.30000000000 0.30000000000 0.40000000000
1
3716
by: Martin Pöpping | last post by:
Hello, I´ve a problem with parsing a double value from an xml file. My code looks like this: int concept_id; double rank; XmlElement root = documentXMLString.DocumentElement; XmlNodeList records = root.ChildNodes;
3
2134
by: ishwarbg | last post by:
Hi Everyone, I have a .Net Application, through which I am invoking a function from a legacy DLL developed in C++. My structure in C# contains some data of type double which I need to pass to to the DLL to get some results back from it. My Structure In C# looks like this: public struct InputPurchaseOrder { public System.String poJobName;
3
3869
by: devecibasi | last post by:
Hi, I am trying to use ShellExecute function to invoke the ax program. The code below works perfect: ShellExecute(0&, "open", "ax.exe", "C:\2runtemp2.run", "C:\axfolder", 5) The code below does NOT work: ShellExecute(0&, "open", "ax.exe", "C:\Documents and Settings\jon\Desktop\requiredfiles\2runtemp2.run", "C:\axfolder", 5)
0
9903
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9754
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10692
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10767
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9526
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7927
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7084
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5952
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4567
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.