473,748 Members | 8,760 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Double printf format...

in program below

#include <stdio.h>
int main()
{
int id = 123, io = 0123, ih = 0x123;
long ld = 1234567L, lo = 01234567l, lh = 0X1234567L;
float f = 123.456f;
double d = 01234.56789L;

printf("id = %d\t%o\t%x\nio = %d\t%o\t%x\nih = %d\t%O\t%X\n",
id, id, id, io, io, io, ih, ih, ih);
printf("ld = %ld\t%lo\t%lx\n lo = %ld\t%lo\t%lx\n lh = %ld\t%lo\t%l\n" ,
ld, ld, ld, lo, lo, lo, lh, lh, lh);
printf("f = %lf\t%le\t%lg\n d = %lf\t%lE\t%lG\n ", f, f, f, d, d, d);
return 0;
}

the output got is:
id = 123 173 7b
io = 83 123 53
ih = 291 %O 123
ld = 1234567 4553207 12d687
lo = 342391 1234567 53977
lh = 19088743 110642547 1234567
f = 123.456001 1.234560e+02 123.456
d = 1234.567890 1.234568E+03 1234.57

why is there a %O in line 3 instead of octal o/p expected?
and in line for d the last o/p is 1234.57. but %g is either %lf or %le
right? so if it is %lf then why is it 1234.57 instead of 1234.56789?

thanks
Mar 13 '08
12 3562
ri*****@cogsci. ed.ac.uk (Richard Tobin) writes:
In article <EO************ *************** ***@bt.com>,
Richard Heathfield <rj*@see.sig.in validwrote:
>>>1999-2008: Almost the entire universe ignores C99 completely.
>>This reflects your personal opinion more accurately than it describes
the truth.
>>Well, actually it reflects my personal understanding of the truth. The only
validated C99 compilers I know about are:

The absence of validated C99 compilers doesn't mean that the universe
is completely ignoring C99. For example, I can use inline functions
or VLAs with fair confidence that they will be available, and
sufficiently compatible, on all the systems I care about. I don't
think this would be true without the existence of C99.
I think it would be true regardless. They existed relatively widely
before C99, AFAICT (with "inline"'s semantics usually being based on
C++'s rules).

--
Just my 2¢, of course
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/
Mar 14 '08 #11
Richard Heathfield wrote:
Richard Tobin said:

<snip>
>The absence of validated C99 compilers doesn't mean that the
universe is completely ignoring C99. For example, I can use
inline functions or VLAs with fair confidence that they will
be available, and sufficiently compatible, on all the systems
I care about. I don't think this would be true without the
existence of C99.

Understood, but the difficulty is in identifying which features
of C99 can be used "portably". We sure could use a central
reference, listing C99 features down the left, compilers across
the top, and ticks in the boxes where the feature has been
implemented according to C99 semantics. That way, maybe people
could start to use C99 features with some degree of confidence
that they will be portable to "all the systems I care about",
for various values of "I".
There are two primary areas in which standards are useful. One is
in specifying what is needed to process some source code. Another
is in specifying what features source code can use.

For the first, there is no loss if the source is prepared without
using all features of the standard. The result remains perfectly
portable.

For the second, things are more complicated. If the writer wants
to maximize portability he can write to the C90 standard, as you
do. This requires checking features used against that standard,
and things can slip through. More often the writer uses the C99
standard for checking, and then eliminates things he knows are not
available in C90. Errors can abound.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Mar 14 '08 #12
naunetr <wi************ @roadtonowhere. invalidwrote:
>
sorry got it confused with scanf! but why is there a %F too? shouldn't %f
be enough?
%F was new in C99. It differs from %f in the treatment of exceptional
values: %F produces INF, INFINITY, or NAN whereas %f produces inf,
infinity, or nan.

-Larry Jones

In a minute, you and I are going to settle this out of doors. -- Calvin
Mar 14 '08 #13

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

Similar topics

6
30163
by: J | last post by:
Would anyone know if there a type tag to format a double? I have f for floating point, but cannot find one for double.
5
23083
by: Piotr B. | last post by:
Hello, I use MingGW g++ 3.2.3 on Windows 2000/AMD Athlon XP. I tried to output a "long double" variable using stdio printf(). I've tried various %formats (%llf, %Lf etc.), but none of them worked... The same source compiled with Borland C++Builder 5.0 works for %Lf format. How to get the same results with MinGW g++ ?
3
3229
by: Hans Ginzel | last post by:
Hello, let us consider function int foo(char *name, void *data) { ... printf(name, data); /* Should be *data? */ ... }
10
18768
by: Bryan Parkoff | last post by:
The guideline says to use %f in printf() function using the keyword float and double. For example float a = 1.2345; double b = 5.166666667; printf("%.2f\n %f\n", a, b);
67
9908
by: lcw1964 | last post by:
This may be in the category of bush-league rudimentary, but I am quite perplexed on this and diligent Googling has not provided me with a clear straight answer--perhaps I don't know how to ask the quesion. I have begun to familiarize myself here with the gcc compiler in a win32 environment, in the form of MinGW using both Dev C++ and MSYS as interfaces. I have recompiled some old math code that uses long double types throughout and...
17
2511
by: arindam.mukerjee | last post by:
I was running code like: #include <stdio.h> int main() { printf("%f\n", 9/5); return 0; }
25
1894
by: Digital Puer | last post by:
I'm getting a very weird bit corruption in a double. I am on an Intel Red Hat Linux box. uname -a returns: Linux foo.com 2.6.9-34.0.2.ELsmp #1 SMP Fri Jun 30 10:33:58 EDT 2006 i686 i686 i386 GNU/Linux I have a "double" variable that is set to 0.00. Some number crunching then occurs, and later on, when I printf this variable with printf("%f"), I am getting 0.00000. However, when I compare
9
1843
by: nsa.usa | last post by:
Hi, Converting a double to int by doing h=(int)(j)in the below code doesn't give the expected result. I'm trying to create 32 random numbers from 1 to 36. So as you see in the output, I get f.ex. in the first line j=10.000000 but converted to int is equals h=1103175862 ???? what gives? please help, I have a headache now, I read the faq it doesn't help :-( Cheers and thanks!, Tobias
6
16739
by: RoS | last post by:
the format for conversion of double in the function printf is "%f" or "%lf" or both? for example printf("%f", (double)0.0); printf("%lf", (double)0.0); are both ok? Good morning Thank you
6
9224
by: amarapreet | last post by:
hi gcc 3.4 says in a warning that %lf is not recognized as a scanf format specifier is this right if so how to read in a double using scanf thanks
0
8991
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
8831
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,...
1
9325
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
8244
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
6796
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
6076
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
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
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
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.