[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • Last Modified:

help on command line

i wnat to reed two filenames a letter and two numbers off the command line, the file names i can get, but am unsure how to convert argv[3] which is a char on the command line ie E or D and i wnat tio be able to do an if on themm but i am unable to say if argv[3]='E' which i want to i also need to be able to say 10*argv[4] which is the first number
0
kplonk
Asked:
kplonk
1 Solution
 
abancroftCommented:
There are several C runtime functions to convert strings to numbers.

To convert string to int: atoi().
To convert string to double: atof().

e.g. (assuming integers)
if (argv[3]=='E')
  myint = 10 * atoi(argv[4]);
0
 
smartinoCommented:
try to use getopts. It is much more versatile in parsing command line arguments. Check the man page.
0
 
ozoCommented:
if( argv[3][0]=='E' )
0
 
hernaniCommented:
Form the above comments you can assemble the correct answer:

int my_int = 0;

if(argv[3][0]=='E') {
  my_int = 10 * atoi(argv[4]);
}
0
 
kplonkAuthor Commented:
thanks for that
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now