473,382 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

command line arguments

how to pass the command line arguments in c
Aug 17 '07 #1
6 1823
gpraghuram
1,275 Expert 1GB
how to pass the command line arguments in c
U shuld do this using argc and argv.
u will get a clear idea about this if u study any C book.

Raghuram
Aug 17 '07 #2
hello.....

I am little bit confused with the implementation of command line argument. Actually i want to know why they have invented this feature... Is there is any real reason to implement this... There r other handy features available why they gone with it........... This is not dealing with any C,C++ or unix... I want to know generally...........

Plaese help me guys...........
Aug 17 '07 #3
On C, you can pass command line using something like this:

Expand|Select|Wrap|Line Numbers
  1. int
  2. main(int argc, char * argv[])
  3. {
  4. int i;
  5.  
  6. printf("The arguments of %s are %d, and they are:\n",argv[0],argc-1);
  7.  
  8. for (i = 0 ;  argv[i] != NULL ; i++ )
  9.  
  10. printf("%d: %s\n",i,argv[i]);
  11.  
  12. return 0;
  13. }
on argc are strored the amount of argmuments of the program, and on argv[], the pointers to the strings that are the arguments. By deafult, the name of the program is recibed in the first place like an argument, and the array of pointers to the arguments is finished by a NULL.

you can use pepe and jose instead of argc and argv, they are used with that name just by convention.

Try to compile it and you will see.

Yours,
DarkArtanis
Aug 19 '07 #4
JosAH
11,448 Expert 8TB
hello.....

I am little bit confused with the implementation of command line argument. Actually i want to know why they have invented this feature... Is there is any real reason to implement this... There r other handy features available why they gone with it........... This is not dealing with any C,C++ or unix... I want to know generally...........

Plaese help me guys...........
You obviously are a post-unix person. Compare those command line arguments
and the command itself as the parameters to a function and the function.

Together with IO (and their redirection) and the piping of commands they are
the building blocks of zillions of useful applications and services all over the world.

GUIs are just there for human beings and human beings are proven unreliable
when it comes to consistency so we won't let them start a second process when
the first one has finished and we certainly don't trust them to carry over results
from one process to the other ;-)

kind regards,

Jos
Aug 19 '07 #5
kalar
82
Some informations you can see here http://publications.gbdirect.co.uk/c...s_to_main.html

We use command line arguments for many reasons.One example is to pass the name of a file into the programm.As an example we type(in LInux) : [PHP]./progr scores.txt alive.txt[/PHP]

progr : is the name of the programm
scores.txt and alive.txt : are the two arguments we pass to the programm.In this example scores.txt and alive.txt are the names of two files we want to process

argc : is argument counter (bigger than 1)
argv : argument vector

argv[0] : is always the name of programm
for this reason argc must be bigger than 1
In this example:
argv[1] : is the scores.txt
arg[v2] : is the alive.txt
Aug 19 '07 #6
weaknessforcats
9,208 Expert Mod 8TB
I am little bit confused with the implementation of command line argument. Actually i want to know why they have invented this feature...
That was done in 1972. The smallest computer was the size of a two-car garage and only had a console.

ANS continues to require console support.

Consoles had all but disappeared but there remains a cult following.
Aug 20 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Hari | last post by:
can i have command line arguments in VS.NET applicatio? if yes how? Can i have some code snippets of the above functionality? I know we can acjieve this in console application form command...
6
by: Jon Hewer | last post by:
hi i am writing a little script and currently implementing command line arguments following the guide by mark pilgrim from dive into python; ...
7
by: Steve M | last post by:
I'm trying to invoke a Java command-line program from my Python program on Windows XP. I cannot get the paths in one of the arguments to work right. The instructions for the program describe the...
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...
1
by: amirmira | last post by:
I would like to set command line arguments to a service at install time. I need to do this because I need to get information from different registry locations depending on my command line argument....
1
by: Rune Jacobsen | last post by:
Hi, I've been trying to figure this one out, but my experience just doesn't have what it takes... :| I am writing an application that reads an XML file and displays the contents in various...
4
by: Roland | last post by:
Hi, I am developing a C++ project and want to pass some command line arguments in VS .NET 2003. I am in debug mode, the configuration is set to Debug and I entered my argument list in Project ->...
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...
2
by: Milan | last post by:
Hi, Please guide me how to set command line argument and how to retrive command line argument. Senario: vb.net application should be able to execute from command prompt by passing login and...
7
by: Jwe | last post by:
Hi, I've written a program which has both a command line interface and Windows form interface, however it isn't quite working correctly. When run from command line with no arguments it should...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.