LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-21-2013, 05:12 AM   #1
displace
Member
 
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 268

Rep: Reputation: 25
[C] Preferred way to parse command line arguments/parameters?


Hey!

I haven't programmed in a while, but I'm currently looking into writing a command line application for linux. I'll be using C or C++, and I'd like to know, if there is a nice way to parse the command line arguments in the program. I've seen some tutorials suggest the use of argv/argc directly while others suggest to use headers like getopt, and yet another suggests to use an external library. I'd like to stick to ease of use, but I don't want any new dependencies for my app.

Are there any standard/recommended/popular ways to parse command line parameters in C (or C++)? I just need some directions/hints/suggestions.

You know, the likes of:
someapp -j manual -u 23 --folder '/home/user/somefolder' -v --skip-tests -n


Regards!
 
Old 12-21-2013, 06:01 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
I'd suggest starting with getopt_long(3).
 
Old 12-26-2013, 02:38 PM   #3
hoholala
LQ Newbie
 
Registered: Sep 2013
Distribution: Parabola GNU/linux-libre
Posts: 13

Rep: Reputation: Disabled
Use getopt and getopt_long
Web: http://www.gnu.org/software/libc/man...pt.html#Getopt
Local: run `info libc getopt'
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command line arguments bioinformatics_guy Linux - Newbie 2 02-12-2009 07:26 AM
need some help regarding command line arguments kristam269 Linux - General 1 01-23-2007 09:40 AM
command line arguments nickraj Programming 6 09-11-2006 01:01 PM
Command line arguments?? almagerenia Linux - Newbie 1 09-08-2006 04:05 AM
command line arguments containing ( Lotharster Linux - Newbie 3 01-05-2006 08:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration