473,395 Members | 2,689 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,395 software developers and data experts.

What is command line arguments? how should i declare it? what is its use?

command line arguments
Jul 15 '10 #1
3 1572
weaknessforcats
9,208 Expert Mod 8TB
Command line arguments are used when you run your program from the OS command prompt:

c:\>myprog.exe filename.txt

Here a program named myprog has an argument that is a file name. Maybe the program will read or write the file. Without this, the program would need you to enter the file name as part of the program.

Basically, any data the program needs in order to run can be passed as a command line argument. These arguments are passed to main:

Expand|Select|Wrap|Line Numbers
  1. int main(int argc, char* argv[])
  2. {
  3.  
  4.  
  5. }
argc is the number of arguments. In our example, there are 2 arguments:myprog.exe and filename.txt. You use argc to tell you which arguments you are using:

argv[0] is myprog.exe
argv[1] is filename.txt

In the program if you fopen argv[1] you will be opening filename.txt.
Jul 15 '10 #2
@weaknessforcats
only the integer and a character pointer can be passed through the main function?
Jul 15 '10 #3
Banfa
9,065 Expert Mod 8TB
Yes, all data supplied by the user from the command line or console is always in text form. You can pass digits but you will need to convert them to binary from text in order to use them.
Jul 15 '10 #4

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...
1
by: rforman1 | last post by:
I have found many threads with this question asked and ostensibly answered, but none with an example of how exactly to do it. Help! I know that in order to set up the values of command line...
8
by: Ian Malone | last post by:
Sorry if this is a FAQ, but I had a quick look through the FAQ Lite and couldn't see it. Googling gives inconsistent answers. I'm coming from a C background. In C if I want to use 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...
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...
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....
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 ->...
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...
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.