472,972 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

strtod( )

Since I've been told that char *argv[] or char **argv[] must be the
second parameter to main's command line structure I have turned to strtod( )
but can't get it to work so far. This function is probably used alot but I
obviously am not using it right.

#include <stdio.h>

int main(int argc, char **argv) {
if (argc != 3) {

fprintf(stderr,"usage error");
}
strtod(argv[1],(char**);
strtod(argv[2],(char**);

printf("%f"argcv[1],"divided by ","%f",argv[2]," is
",argv[1]/argv[2]);
}

This is one of many tried of strtod( ) I've tried on my own.

Bill
Mar 25 '08 #1
8 3451
Bill Cunningham wrote:
Since I've been told that char *argv[] or char **argv[] must be the
second parameter to main's command line structure I have turned to strtod( )
but can't get it to work so far. This function is probably used alot but I
obviously am not using it right.

#include <stdio.h>

int main(int argc, char **argv) {
if (argc != 3) {

fprintf(stderr,"usage error");
}
strtod(argv[1],(char**);
How could this compile?

strtod() returns a value, which you are discarding.

The simplest use of strtod() has NULL for the second parameter, for example:

double d = strtod( argv[1], NULL );

You should clear errno and check its value for zero after the call to
make sure the conversion was successful.

--
Ian Collins.
Mar 25 '08 #2
How could this compile?

strtod() returns a value, which you are discarding.

The simplest use of strtod() has NULL for the second parameter, for
example:

double d = strtod( argv[1], NULL );
I read or thought I read the second argument was a pointer.
You should clear errno and check its value for zero after the call to
make sure the conversion was successful.

--
Ian Collins.

Mar 25 '08 #3
So I guess it's char *argv[] and can't be double *argv[] if doubles
are wanted then.

Mar 25 '08 #4
no****@nspam.com wrote:
So I guess it's char *argv[] and can't be double *argv[] if doubles
are wanted then.
What can? What or who are you replying to?

--
Ian Collins.
Mar 25 '08 #5
On Tue, 25 Mar 2008 01:06:49 GMT, "Bill Cunningham" <no****@nspam.com>
wrote:
Since I've been told that char *argv[] or char **argv[] must be the
I doubt if anyone has suggested the second form. If they have, you
have just learned an important Usenet lesson: some advice is wrong.
More likely, however, is the lesson that in programming you need to
pay more attention to the details. The second form of this parameter
is char** argv. The difference is not irrelevant...
>second parameter to main's command line structure I have turned to strtod( )
but can't get it to work so far. This function is probably used alot but I
obviously am not using it right.

#include <stdio.h>

int main(int argc, char **argv) {
But apparently you knew the correct form. So maybe your opening
sentence was sucker bait and you hooked me.
if (argc != 3) {

fprintf(stderr,"usage error");
You have been here for a while. How many times have you seen messages
discussing the potential problems caused by not including a \n at the
end of the string to be displayed?
}
strtod(argv[1],(char**);
You might want to spend some time learning to balance your
parentheses.

You might also want to practice indenting consistently. Code that
easier to read is easier to debug.

When you look up a function in your reference, it should also tell you
which headers you need to include to use that function. That
information is not superfluous.
strtod(argv[2],(char**);

printf("%f"argcv[1],"divided by ","%f",argv[2]," is
",argv[1]/argv[2]);
This is just mind boggling. Do you really think you can just ignore
the function prototypes? Do you really think that placing arguments
adjacent to each other with no intervening punctuation will magically
convert and concatenate values? Do you really think two conversion
specifications are adequate for printing at least three variable
values?
>}
Where is the int that main is supposed to return?
>
This is one of many tried of strtod( ) I've tried on my own.
Forget strtod. Try to get main correct first.

Remove del for email
Mar 25 '08 #6
Barry Schwarz wrote:
On Tue, 25 Mar 2008 01:06:49 GMT, "Bill Cunningham" <no****@nspam.com>
wrote:
[blither]
Forget strtod. Try to get main correct first.

I recommend not wasting your time. He's supposedly been learning C
since 2004. Nothing you say will make the least impression. Most likely
he will just be moving on to some new problem he doesn't understand.

Until Cunningham agrees to learn C by defined rules, including working
one problem at a time through to success, and looking up functions in
manuals or online, people should just shut him out.

Yes, I'm an ol' meany-head because I have no sympathy for his supposed
learning disability. Well, if that prevents him from learning C at all,
which it seems to, then he should find some more productive use of his
time.


Brian
Mar 25 '08 #7
[snip]
>>#include <stdio.h>

int main(int argc, char **argv) {

But apparently you knew the correct form. So maybe your opening
sentence was sucker bait and you hooked me.
The above statement you refer to is a misprint.

Bill
Mar 25 '08 #8
On Mon, 24 Mar 2008 22:25:15 -0700, Barry Schwarz <sc******@dqel.com>
wrote:
On Tue, 25 Mar 2008 01:06:49 GMT, "Bill Cunningham" <no****@nspam.com>
wrote:
<snip other points>
printf("%f"argcv[1],"divided by ","%f",argv[2]," is
",argv[1]/argv[2]);

This is just mind boggling. Do you really think you can just ignore
the function prototypes?
If the juxtaposition worked (see next) this wouldn't violate the
prototype -- only the semantics for printf's varargs, which aren't in
the prototype. (Since *printf/scanf are standard, the compiler can
know about them and e.g. gcc does, but not from the prototype.)
Do you really think that placing arguments
adjacent to each other with no intervening punctuation will magically
convert and concatenate values?
It does in awk, whose surface syntax is enough like C (at least the C
when it was created, K&R1) that on a cloudy night, in a fog, with your
eyes closed, you might confuse them. <G>
Do you really think two conversion
specifications are adequate for printing at least three variable
values?
If the (inconsistent and probably unintended, and misspelled)
juxtaposition had in fact done one conversion, you would have two
conversion specifiers and two remaining data items -- if there were
some way for printf distinguish which was intended to be which, which
there isn't. (Plus the fact, already discussed, that argv[i] has to be
a string and can't be a float or double.)

- formerly david.thompson1 || achar(64) || worldnet.att.net
Apr 7 '08 #9

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

Similar topics

3
by: Leslaw Bieniasz | last post by:
Cracow, 20.09.2004 Hi, I want to replace: char *text; double val = strtod(text,NULL); by an equivalent using std::string in the place of char *.
1
by: Mathieu Malaterre | last post by:
Hello, I would like to have some advices on this problem I am having. In my code I have hardcoded a string like: const char foo = "11 0.438482 "; I was then calling strtod to transform it...
21
by: Marky C | last post by:
atof is not working. double a = atof("12.345"); a gets set to 12.000 I am working on a toshiba micro. The data map has no space allocated to it for dynamic memory. Does anyone have an...
9
by: Adam Warner | last post by:
Hi all, Message ID <c1qo3f0tro@enews2.newsguy.com> is one of many informative articles by Chris Torek about C. The particular message discusses aliasing and concludes with this paragraph: ...
4
by: Gary Wessle | last post by:
Hi I have a vector<stringwhich holds numbers, I need to loop and printout those numbers + a value as doubles . typedef vector<string>::const_iterator vs_itr; for(vs_itr i=vect.begin();...
18
by: coder | last post by:
Hi experts, Is the following usage of strtod okay (p is a char pointer): value = strtod(p, &p); Is it possible that this would evoke undefined behaviour? Or should I use a temporary pointer...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.