Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Question about Type Conversion 1

Status
Not open for further replies.

gr8gonzo

MIS
Feb 6, 2001
21
0
0
US
I have a C program that has the following:

... misc header code ...

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

some_function(argv[3]);
some_other_function(argv[4]);
price = 50.00;

}

Now, I specify a few options as parameters when I run the program like: program "value1" "value2"

I want to be able to specify price, which is a double, via the command line. But argv is already declared as char, so it is giving me problems. How can I take argv[5] and parse it/convert it into a value (double or integer or something) ?

- Jonathan
 
see sscanf:

float price;
sscanf(arcv[xxx],"%f",&price);

also there exist atoi family functions. They also does such type of conversions. Ion Filipski
1c.bmp


filipski@excite.com
 
Hi,

In my humble opinion, using strtod() and strtoul() is better than usin atof() function as strto... functions provide better error detection than ato... functions.

Regards,
SwapSawe.:cool:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top