473,513 Members | 10,313 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Command Prompt input

114 New Member
How do u get input from the command prompt as a program argument? like there is the javac program that accepts arguments to work.
Sep 24 '07 #1
5 1983
Ganon11
3,652 Recognized Expert Specialist
I believe you use

Expand|Select|Wrap|Line Numbers
  1. int main(int argc, char *argv[])
The command line arguments are stored in argv. So if you typed:

Expand|Select|Wrap|Line Numbers
  1. myProg.exe My name is Ganon.
then argv[1] contains "My\0", argv[2] contains "name\0", and so on.

argc is the number of arguments passed; in the previous example, argc holds 4.
Sep 24 '07 #2
Banfa
9,065 Recognized Expert Moderator Expert
Expand|Select|Wrap|Line Numbers
  1. myProg.exe My name is Ganon.
then argv[1] contains "My\0", argv[2] contains "name\0", and so on.

argc is the number of arguments passed; in the previous example, argc holds 4.
Remember that argv[0] contains the program name "myProg.exe" so in your example argc actual holds 5.
Sep 24 '07 #3
Firecore
114 New Member
Um.
I didnt really get it.
can u plz sho me an example?
Im not that smart.
Sep 24 '07 #4
Banfa
9,065 Recognized Expert Moderator Expert
Compile and run this, put something(anything) on the command line
Expand|Select|Wrap|Line Numbers
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4.  
  5. int main(int argc, char **argv)
  6. {
  7.     int ix;
  8.  
  9.     for(ix=0; ix<argc; ix++)
  10.     {
  11.         printf("%3d: %s\n", ix, argv[ix]);
  12.     }
  13.  
  14.     return 0;
  15. }
  16.  
Sep 24 '07 #5
forse
7 New Member
Check out Using command-line arguments in C++
Sep 24 '07 #6

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

Similar topics

3
1840
by: Kim Ipsen | last post by:
Hi. I don't know if this possible but how would you do it if you wanted to send commands til the comman prompt (and preferrably also receive the output from the command prompt - though not...
7
6601
by: David A. Osborn | last post by:
I am current writing a console program that takes two file paths as command line input. I get the command line input using the following code: parameter = Split(Command()) input = parameter(0)...
17
7884
by: comp.lang.tcl | last post by:
The TCL command I am using will do a command-line action on a PHP script: set cannotRunPHP I have to do it this way as both the TCL script and the PHP script run as CLI. However, "info.php"...
34
6822
by: Roman Mashak | last post by:
Hello, All! I'm implementing simple CLI (flat model, no tree-style menu etc.). Command line looks like this: <command> <param1> <param2> ... <paramN> (where N=1..4) And idea is pretty simple: ...
11
8754
by: gert365 | last post by:
I'm working on a scirpt to be used on a windows machine and I need to automate a user's input on the command prompt. For example I'm using os.system('mycommand') to excute the commands I want. ...
3
2259
by: Steven | last post by:
I am using VC++ 6.0 to build a windows based application, however, my application allows user to input command arguments in the dos prompt windows. I want to have a warning message for user if they...
6
5599
by: evantri | last post by:
I am developing a program that prompt the input from the command line argument. For example, this is the lists of command line arguments that I want to include: -fish -cat -dog -animal All...
1
2165
by: viswasai2k | last post by:
I have created a example.exe. And i am running this example.exe in the command prompt. when the example.exe is running i have to give a string input and coming next line another user input to...
3
5096
by: kimiraikkonen | last post by:
Hi experts, I just want to ask a simple procedure of my simple form. My form has a input textbox and a button. I want this if you can help me: Application user types a command prompt command...
2
4269
by: megatrious | last post by:
I have a windows command line tool that accepts certain input parameters and runs a process and displays a report. I want to develop a Java GUI for that tool. Input parameters need to be given in...
0
7153
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
7373
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
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7519
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...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1585
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.