The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Why does the 'ps' command with -u option not working? ElCaito SUN Solaris 4 02-26-2006 07:14 PM
Usage of optarg sveera Shell Programming and Scripting 5 07-19-2005 06:21 PM
option for ls command eloquent99 UNIX for Dummies Questions & Answers 1 02-07-2003 06:27 PM
tar command with compress option... tomapam UNIX for Dummies Questions & Answers 3 10-11-2002 12:56 PM
-c option in ping command Deepa Shell Programming and Scripting 3 05-31-2002 06:05 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-17-2009
Dedalus Dedalus is offline
Registered User
  
 

Join Date: May 2009
Location: Italy/France
Posts: 60
Thumbs up command line option: optarg

Hi

I'm learning how to add in programm another option by command line.
For example in the "my_prog" i want to add a " -k " option and then write a number.
I mean:
Code:
my_prog -k 50
and the i should use the number 50.
I'm reading about getopt_long and optarg, and what i have done in the code is to add k in the getop_long as:
Code:
c = getopt_long (*pargc, argv, "B:T:z:k:gpdht", long_options, &option_index)
and the k option in the switch as:

Code:
    case 'k':
      number_i_want = optarg;
      routine_that_use_number_i_want(number_i_want);
      break;
the program run but it doesn't work appropriately. I think the problem is in optarg that should point to a string.
Anyone can help?

Thanks

D.

-----Post Update-----

Sorry I got it.

All i have to do is translate the char to int with the atoi() function.
Code:
number_i_want=atoi(optarg)
Now seems like works!

D.

Last edited by otheus; 06-18-2009 at 08:42 AM..
Sponsored Links
Bits Awarded / Charged to Dedalus for this Post
Date User Comment Amount
06-18-2009 otheus For solving own problem and posting it on the forum! 1,000
Reply

Bookmarks

Tags
command-line, getopt_long, optarg

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 04:14 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0