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\nlo = %ld\t%lo\t%lx\nlh = %ld\t%lo\t%l\n",
ld, ld, ld, lo, lo, lo, lh, lh, lh);
printf("f = %lf\t%le\t%lg\nd = %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 12 3530
naunetr wrote:
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\nlo = %ld\t%lo\t%lx\nlh =
%ld\t%lo\t%l\n",
ld, ld, ld, lo, lo, lo, lh, lh, lh);
printf("f = %lf\t%le\t%lg\nd = %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?
The format specifier for octal output is %o, not %O. In C case is
important.
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?
I think that's a precision issue.
naunetr wrote:
[...]
why is there a %O in line 3 instead of octal o/p expected?
Because you put it there. The relevant fragment of the format string is
ih = %d\t%O\t%X\n
Notice the %O in the string above? There is no %O conversion specifier,
and the "octal" conversion specifier is %o
thanks Lew. is there a specifier which will put a 0 in front off the octal
number? like 0x for %#x?
What about "0%o" and "0x%x"?
[...]
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
In article <fr**********@registered.motzarella.org>,
naunetr <wi************@roadtonowhere.invalidwrote:
>thanks Lew. is there a specifier which will put a 0 in front off the octal number? like 0x for %#x?
%#o
C89 4.9.6.1 The fprintf Function
# The result is to be converted to an "alternate form." For o
conversion, it increases the precision to force the first digit
of the result to be a zero. For x (or X) conversion, a
nonzero result will have 0x (or 0X) prefixed to it. [...]
>sorry got it confused with scanf! but why is there a %F too? shouldn't %f be enough?
C89 does not have %F (but does have %E and %G). %E and %G use a
capital E for the exponent signifier instead of a lower-case e
but are otherwise the same as %e and %g respectively.
--
"The quirks and arbitrariness we observe force us to the
conclusion that ours is not the only universe." -- Walter Kistler
On Thu, 13 Mar 2008 19:16:27 +0000, ro******@ibd.nrc-cnrc.gc.ca (Walter
Roberson) wrote:
On Thu, 13 Mar 2008 19:16:27 +0000, ro******@ibd.nrc-cnrc.gc.ca (Walter
Roberson) wrote:
In article <fr**********@registered.motzarella.org>, naunetr
<wi************@roadtonowhere.invalidwrote:
>>thanks Lew. is there a specifier which will put a 0 in front off the octal number? like 0x for %#x?
%#o
oops! thought that works only for hex specifier %x.
C89 4.9.6.1 The fprintf Function
# The result is to be converted to an "alternate form." For o
conversion, it increases the precision to force the first digit of
the result to be a zero. For x (or X) conversion, a nonzero result
will have 0x (or 0X) prefixed to it. [...]
>>sorry got it confused with scanf! but why is there a %F too? shouldn't %f be enough?
C89 does not have %F (but does have %E and %G). %E and %G use a capital
E for the exponent signifier instead of a lower-case e but are otherwise
the same as %e and %g respectively.
thanks Walter. by "C89" you mean ANSI C yes?
naunetr said:
On Thu, 13 Mar 2008 19:16:27 +0000, ro******@ibd.nrc-cnrc.gc.ca (Walter
Roberson) wrote:
<snip>
>C89 does not have %F (but does have %E and %G). %E and %G use a capital E for the exponent signifier instead of a lower-case e but are otherwise the same as %e and %g respectively.
thanks Walter. by "C89" you mean ANSI C yes?
Almost certainly it's the other way around - that is, by "ANSI C" you mean
C89.
Quick history for you:
dawnatime: R invents C.
dawnatime + a bit: K says "that's cool, let's do a book on it".
1978: K&R published.
1980s: ANSI undertake a standardisation process which culminates in:
1988: K&R2 (based on draft-proposed ANSI C) published.
1989: ANSI formally standardises C (this is C89, which is what you've got)
1990: ISO adopts the ANSI C Standard internationally (C90)
1999: ISO formally re-standardises C (C99)
2000: ANSI adopts C99
1999-2008: Almost the entire universe ignores C99 completely.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Richard Heathfield <rj*@see.sig.invalidwrites:
Quick history for you:
<snip history>
1999-2008: Almost the entire universe ignores C99 completely.
This reflects your personal opinion more accurately than it describes
the truth. It *is* true, of course, but uninterestingly true since
"almost the entire universe ignores X completely" is true for a very
large set of Xs -- including C90!
--
Ben.
Ben Bacarisse said:
Richard Heathfield <rj*@see.sig.invalidwrites:
>Quick history for you:
<snip history>
>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:
EDG (Pentium PIII, Linux 7.x series)
IBM XL (IBM POWER PC_970, AIX 5.3h)
IBM Visual Age (IBM PowerPC systems w/ CHRP system architecture, AIX 5L for
POWER, Version 5.2)
LMPCC C99 Compiler for Linux / PowerPC (Motorola PowerPC MPC7455, Terrasoft
Solutions, Yellow Dog Linux 3.0)
Sun Studio 9 (SPARC Ultra/Intel x86/AMD 64, Solaris 10)
(Some of these depend on the validated C99-conforming Dinkum Unabridged
Library.)
Data source: http://www.peren.com/pages/cvsa_isocvpl.htm
I don't have time to research into how many C90-conforming compilers there
are, but ISTR that there are a hundred or so. Does anyone have any better
data?
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
In article <EO******************************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>>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.
-- Richard
--
:wq
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".
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999 ri*****@cogsci.ed.ac.uk (Richard Tobin) writes:
In article <EO******************************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>>>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/
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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.
|
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...
|
by: Hans Ginzel |
last post by:
Hello,
let us consider function
int foo(char *name, void *data) {
...
printf(name, data); /* Should be *data? */
...
}
|
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);
|
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...
|
by: arindam.mukerjee |
last post by:
I was running code like:
#include <stdio.h>
int main()
{
printf("%f\n", 9/5);
return 0;
}
|
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...
|
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....
|
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
|
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
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |