IT Community - Software Programming, Web Development and Technical Support

How do I access command-line arguments?

This is a discussion on How do I access command-line arguments? within the C and C++ Programming forums, part of the Software Development category; Hi, Can anyone tell me general ways to access command-line arguments? plz give an example. Thanks, Prasath.K...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C and C++ Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-19-2007, 12:21 AM
prasath prasath is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Location: Chennai
Posts: 173
prasath is on a distinguished road
Smile How do I access command-line arguments?

Hi,

Can anyone tell me general ways to access command-line arguments? plz give an example.

Thanks,
Prasath.K

Last edited by Booom : 08-18-2007 at 01:23 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-17-2007, 11:46 PM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: How do I access command-line arguments?

hey,

Command line arguments are space seperated character strings. In our contest, you enter these strings in a special window in the client.

These arguments are given to your program in specially defined character arrays. In C/C++ the number of arguments is also passed into your program in a specially declared integer. In java, this can be obtained by getting the length of the argument array, as shown below.

In the code skeletons (provided in the client), you can access the command line arguments in the following ways.:


Example of using command line args with C++

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
int i,j;

for (i = 1; i < argc; i++)
printf("%s ",argv[i]);

printf("\n");

printf("The first argument as a number is: %d\n", atoi(argv[1]) );

return 0;
}

Java
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I execute a PHP script using command line? sundarraja PHP Programming 0 01-28-2008 02:53 AM
Using PHP from Command Line Sabari PHP Programming 4 12-18-2007 06:42 AM
How do I read command-line arguments with Perl? leoraja8 Perl 3 11-26-2007 06:43 AM
How do I run a php script from the command line itbarota PHP Programming 1 09-11-2007 03:06 AM
How do I read command-line arguments with Perl? sivaramakrishnan Perl 1 07-23-2007 04:50 AM


All times are GMT -7. The time now is 01:53 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0