this sounds really stupid but looked through my notes several times and cannot find what command line arguements are. could someone give me an example.PLEASE.
This is a discussion on command line arguements within the C Programming forums, part of the General Programming Boards category; this sounds really stupid but looked through my notes several times and cannot find what command line arguements are. could ...
this sounds really stupid but looked through my notes several times and cannot find what command line arguements are. could someone give me an example.PLEASE.
Command-line arguments are arguments(parameters) passed into the program when it is run from the command prompt (or passed to the program when a file is dragged and dropped onto an executable in Windows for example).
Let's say you have a program called test.exe and you want to run it with some command-line arguments. At the command prompt you could do something like:
test foo.txt bar.txt
... where foo.txt and bar.txt are the two command-line arguments passed into the program.
I used to be an adventurer like you... then I took an arrow to the knee.
Provided you're in the correct directory where your exe is located. So adding onto simplification where hk_mp5kpdw left, (for Windows)
say your exe named test.exe is stored in C-drive and screamer folder. Then you first go to the command-prompt(some still call it DOS prompt) and then go to the c:\screamer folder and then do what mp5kpdw suggested.![]()
Incase you knew that and you actually needed a programming example, here it is:
Code:#include <stdio.h> int main(int argc, char* argv[]){ /* If arguments have been passed */ if (argc > 0){ /* Prints 1st argument in argv[1] (argv[0] is the name of the .exe file) */ printf("Hello, %s\n",argv[1]); } else{ /* If no arguments were passed... */ printf("Anybody out there?\n"); } return 0; }