473,426 Members | 1,648 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,426 software developers and data experts.

code

I thought I would post this code. It seems to do what I want it to but I
thought I would have it critiqued. I use C89 but I think that maybe some of
the code maybe misplaced. For example, the fopen probably should be under
the strtod's shouldn't it ?

/*code C89 */
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
if (argc != 6) {
puts("print usage error");
exit(EXIT_FAILURE);
}
FILE *fp;
char *error;
double a, b, c, d;
if ((fp = fopen(argv[5], "a")) == NULL)
perror(error);
a = strtod(argv[1], NULL);
b = strtod(argv[2], NULL);
c = strtod(argv[3], NULL);
d = strtod(argv[4], NULL);
fprintf(fp, "%.2f\t%.2f\t%.2f\t%.2f\n", a, b, c, d);
if ((fclose(fp)) == EOF)
perror(error);
return 0;
}

Thanks all.

Bill

Oct 1 '08
52 2666
On Wed, 1 Oct 2008 18:40:07 -0400, "Bill Cunningham" <no****@nspam.invalidwrote:
"Barry Schwarz" <sc******@dqel.comwrote in message
news:rn********************************@4ax.com...
>The dismaying thing is this won't generate a diagnostic and you will
spend the next several messages arguing that it is correct.

I don't think so.
What Barry Schwarz wrote *is* true, though.

The following program builds without any diagnostic messages in either
'c89' or 'c99' mode with gcc 4.2.1:

1 #include <stdio.h>
2 #include <stdlib.h>

3 int
4 main(void)
5 {
6 char *error = '\0';

7 (void)printf("error=%p\n", error);
8 return EXIT_SUCCESS;
9 }

One would probably expect line 6 to issue a diagnostic, but it doesn't.

If line 6 is replaced with

char *error = 1;

then a diagnostic *is* displayed by gcc in both std=c89 and std=c99 mode:

foo.c:7: warning: initialization makes pointer from integer without a cast

It is the special case of an integer that is zero that is, well,
`special'. There is no diagnostic message, and the pointer is
initialized to the system specific value of a null pointer.

Oct 4 '08 #51
On Thu, 02 Oct 2008 15:45:25 -0700, Nate Eldredge <na**@vulcan.lanwrote:
However, there does seem to be a tradition of implementations
including a few joke error codes in <errno.h>. glibc, notably,
includes EGRATUITOUS, EGREGIOUS, EIEIO, and ED ("The experienced user
will know what is wrong"). FreeBSD is a bit more sedate but does
include EDOOFUS. I have always wanted to find an excuse to use one of
these.
Heh!

Well, EDOOFUS isn't exactly a `joke value', because it is *used* in some
parts of the kernel. In my local version of the 8.0-CURRENT source tree
there are at least the following instances:

keramida@kobe:/usr/src/sys$ fgrep -nr EDOOFUS *
boot/efi/libefi/errno.c:89: errno = EDOOFUS;
dev/hwpmc/hwpmc_mod.c:2439: return EDOOFUS; /* programming error */
dev/md/md.c:1102: error = EDOOFUS;
dev/puc/puc.c:445: return (EDOOFUS);
dev/puc/puc_cfg.c:50: error = EDOOFUS;
geom/bde/g_bde_lock.c:414: return (EDOOFUS); /* Programming error */
geom/part/g_part.c:1332: error = EDOOFUS;
geom/part/g_part.c:1365: error = EDOOFUS; /* Prevent bogus uninit. warning. */
geom/part/g_part.c:1798: error = (arg == (uintptr_t)scheme) ? EDOOFUS : arg;
kern/subr_witness.c:1003: return (EDOOFUS);
sys/errno.h:168:#define EDOOFUS 88 /* Programming error */
keramida@kobe:/usr/src/sys$

Reading through a few cases where EDOOFUS appears, it looks more like a
catch-all value, meaning ``Oops! This wasn't meant to _ever_ happen.
Something looks remarkably screwed up, so let's break out of the kernel
and avoid making a more serious mess of anything.''.

Oct 4 '08 #52
Giorgos Keramidas wrote, On 04/10/08 04:27:
On Wed, 1 Oct 2008 18:40:07 -0400, "Bill Cunningham" <no****@nspam.invalidwrote:
>"Barry Schwarz" <sc******@dqel.comwrote in message
news:rn********************************@4ax.com.. .
>>The dismaying thing is this won't generate a diagnostic and you will
spend the next several messages arguing that it is correct.
I don't think so.

What Barry Schwarz wrote *is* true, though.

The following program builds without any diagnostic messages in either
'c89' or 'c99' mode with gcc 4.2.1:

1 #include <stdio.h>
2 #include <stdlib.h>

3 int
4 main(void)
5 {
6 char *error = '\0';

7 (void)printf("error=%p\n", error);
8 return EXIT_SUCCESS;
9 }

One would probably expect line 6 to issue a diagnostic, but it doesn't.
'\0' is just another way of spelling 0. Strange but true.
If line 6 is replaced with

char *error = 1;

then a diagnostic *is* displayed by gcc in both std=c89 and std=c99 mode:

foo.c:7: warning: initialization makes pointer from integer without a cast
That warning is entirely correct. The C standard (all versions) require
a warning.
It is the special case of an integer that is zero that is, well,
`special'. There is no diagnostic message, and the pointer is
initialized to the system specific value of a null pointer.
The special case is specifically an integer *constant* expression that
evaluates to 0, so ((42-42)/42) would also work, and it is guaranteed to
set the pointer to a null pointer whatever than means in terms of bit
patterns. However, the following would not
const int zero = 0;
char *pre = zero;
--
Flash Gordon
If spamming me sent it to sm**@spam.causeway.com
If emailing me use my reply-to address
See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/
Oct 4 '08 #53

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

Similar topics

51
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
9
by: bigoxygen | last post by:
Hi. I'm using a 3 tier FrontController Design for my web application right now. The problem is that I'm finding to have to duplicate a lot of code for similar functions; for example, listing...
4
by: jason | last post by:
Hello. Newbie on SQL and suffering through this. I have two tables created as such: drop table table1; go drop table table2; go
16
by: Dario de Judicibus | last post by:
I'm getting crazy. Look at this code: #include <string.h> #include <stdio.h> #include <iostream.h> using namespace std ; char ini_code = {0xFF, 0xFE} ; char line_sep = {0x20, 0x28} ;
109
by: Andrew Thompson | last post by:
It seems most people get there JS off web sites, which is entirely logical. But it is also a great pity since most of that code is of such poor quality. I was looking through the JS FAQ for any...
5
by: ED | last post by:
I currently have vba code that ranks employees based on their average job time ordered by their region, zone, and job code. I currently have vba code that will cycle through a query and ranks each...
0
by: Namratha Shah \(Nasha\) | last post by:
Hey Guys, Today we are going to look at Code Access Security. Code access security is a feature of .NET that manages code depending on its trust level. If the CLS trusts the code enough to...
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
37
by: Alan Silver | last post by:
Hello, Newbie here, so please forgive what is probably a basic question ... I see a lot of discussion about "code behind", which if I have understood correctly, means that the script code goes...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.