Solved

help on command line

Posted on 2000-03-08
5
160 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
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now