Solved

help on command line

Posted on 2000-03-08
5
166 Views
Last Modified: 2010-04-15
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
Comment
Question by:kplonk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 4

Accepted Solution

by:
abancroft earned 10 total points
ID: 2597055
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
 

Expert Comment

by:smartino
ID: 2597766
try to use getopts. It is much more versatile in parsing command line arguments. Check the man page.
0
 
LVL 84

Expert Comment

by:ozo
ID: 2597825
if( argv[3][0]=='E' )
0
 

Expert Comment

by:hernani
ID: 2598262
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
 

Author Comment

by:kplonk
ID: 2598483
thanks for that
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question