473,738 Members | 9,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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"argc v[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 3489
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.co m 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.c om>
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"argc v[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.c om>
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.c om>
wrote:
<snip other points>
printf("%f"argc v[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.ne t
Apr 7 '08 #9

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

Similar topics

3
5465
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
3019
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 back to double. Unfortunately depending on the LOCALE settings, the strtod could fail.
21
2281
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 idea? Could it be due to the lack of dynamic
9
1971
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: Under these strict type-aliasing rules, casting from (e.g.) "int *" to "short *" is not only quite suspicious, it is also likely to cause puzzling behavior, at least if you expect your "short *" to access or modify your "int". Even the time-honored,...
4
2467
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(); i!=vect.end(); ++i){ cout << *i << '\t' << strtod(*i)+val << '\n';
18
2449
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 and then assign its value to p? Thanks
0
8788
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
9335
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
9263
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,...
1
6751
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
6053
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
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
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
2745
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.