I want to make a program where you have options when you run the program, for example:
your at the dos prompt:
D:\program -f -h
D:\program -f index.htm
Something like that. is there a site that gives a tutorial on how to do that. Thanks!
I want to make a program where you have options when you run the program, for example:
your at the dos prompt:
D:\program -f -h
D:\program -f index.htm
Something like that. is there a site that gives a tutorial on how to do that. Thanks!
the best things in life are simple.
Not sure about a tut, but do a search for Argc & Argv, they're not too hard to use. If you have any books on C, just have a look for them in the index. If you're still stuck I'll post you some code (or I'm sure someone else will).
Declare your main function to pass two parameters, int argc and char *argv[]. You can then use the strings in argv that you passed from the command line.
C:\programName arg1 arg2 arg3
When you start your program use this line:
int main ( int argc, char *argv[] )
From here argv holds 4 strings, "programName", "arg1", "arg2", and "arg3". You can now use them for processing in your program.
-Prelude
My best code is written with the delete key.
Thanks! I found some things, but could you still post some code? Thanks!
the best things in life are simple.
A program that takes your first and last name as arguments and prints them to the screen.
Input:Code:// Pseudocode #include <iostream> using namespace std; int main ( int argc, char **argv ) { if ( argc == 3 ) { cout<<"Your first name is "<<argv[1]<<endl; cout<<"Your last name is "<<argv[2]<<endl; } return EXIT_SUCCESS; }
C:\program Julienne Walker
Output:
Your first name is Julienne
Your last name is Walker
-Prelude
My best code is written with the delete key.
Thanks everyone! That helped!
the best things in life are simple.