473,473 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Command line parameters - argc and argv[]

ern
Is there a standard (or easy) way to parse parameters (configs) that
come from main(int argc, char *argv[]) ?

For example,

If I have the following configurations:

-s <string // pass a string to main

-f <file // pass a file to main

-i <integer // pass an integer to main

-d // set the 'doStuff' flag

as well as being able to send any arbitrary command to main(), are
there any proven methods of parsing the configurations? It seems like
option-parsing code would already exist, but I can't find any. The
option-parsing in the code I'm debugging is messy and unacceptable.
I'd like to start from scratch. For Python minded people, I'm looking
for an equivalent to 'optparse'.

Aug 17 '06 #1
2 3517
ern <er*******@gmail.comwrote:
Is there a standard (or easy) way to parse parameters (configs) that
come from main(int argc, char *argv[]) ?
There's nothing included in the standard library, although it's
certainly possible to implement something that does this in standard
C. If you're on a Unix system, check out getopt(); you can get more
help with that on comp.unix.programmer.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Aug 17 '06 #2
In article <11**********************@i3g2000cwc.googlegroups. com>,
ern <er*******@gmail.comwrote:
>Is there a standard (or easy) way to parse parameters (configs) that
come from main(int argc, char *argv[]) ?
>For example,
If I have the following configurations:
-s <string // pass a string to main
It isn't part of the C language itself, but many systems
provide routines named getopt() or similar; there are fully
portable versions of the routine readily available.

Different option parsers offer different facilities. For example,
many of the getopt() routines do not offer a mechanism to type-check
provided arguments, nor to convert the provided argument from
string to integer (or float, or enumeration type, or whatever): they
just break out the strings and let you deal with the semantics.
--
Is there any thing whereof it may be said, See, this is new? It hath
been already of old time, which was before us. -- Ecclesiastes
Aug 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Bernd Danberg | last post by:
Hi, I have a real strange problem with the command line arguments given to the main-function and together with using std::string: #include <string> int _tmain(int argc, _TCHAR* argv) {...
7
by: qazmlp | last post by:
void func() { // Is it by anyway possible to read the value of the first command line parameter i.e. argv here ? } int main() { func() ; // No command line arguments are passed to func(). }
25
by: David Bernier | last post by:
I'd like to pass on the command line two filenames. As for example: my_executable filename_1 filename_2 I haven't done any C programming with command line arguments so far. I'm familiar...
19
by: linzhenhua1205 | last post by:
I want to parse a string like C program parse the command line into argc & argv. I hope don't use the array the allocate a fix memory first, and don't use the memory allocate function like malloc....
2
by: SunRise | last post by:
Hi I am creating a C Program , to extract only-Printable-characters from a file ( any type of file) and display them. OS: Windows-XP Ple help me to fix the Errors & Warnings and explain...
34
by: Roman Mashak | last post by:
Hello, All! I'm implementing simple CLI (flat model, no tree-style menu etc.). Command line looks like this: <command> <param1> <param2> ... <paramN> (where N=1..4) And idea is pretty simple: ...
3
by: kitty | last post by:
Can i provide for command line switches in c++ ? For example i can say perl readfile.pl -f filename, Is g++ readfile.cc -f filename possible ? Thankyou for all you help,.
40
by: raphfrk | last post by:
I have a program which reads in 3 filenames from the command line prog filename1 filename2 filename3 However, it doesn't work when one of the filenames has spaces in it (due to a directory...
1
by: vutek0328 | last post by:
I have a code of which I need to set parameters in order to run. I'm wondering how I can input the parameters through the command line. ./brownian 10 15 100 200 with each number being a...
17
by: Matt | last post by:
Hello. I'm having a very strange problem that I would like ot check with you guys. Basically whenever I insert the following line into my programme to output the arguments being passed to the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.