• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • 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

Identify and Prevent Potential Cyber-threats

Become the white hat who helps safeguard our interconnected world. Transform your career future by earning your MS in Cybersecurity. WGU’s MSCSIA degree program was designed in collaboration with national intelligence organizations and IT industry leaders.

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