how do i accept command line parameters onto a program running under windows, i understand argv is the number of arguements but for eg - if i wanted to accept a 2 as a command line param and act on it - how do i do it.
tia
how do i accept command line parameters onto a program running under windows, i understand argv is the number of arguements but for eg - if i wanted to accept a 2 as a command line param and act on it - how do i do it.
tia
Monday - what a way to spend a seventh of your life
i thought argc held the number of arguments where argv held the arguments ??
"with a gun barrel between your teeth, you speak only in vowels."
- tyler durden
Welcome back!!!!!
I'm assuming you mean a Win32 Program that uses WinMain???
If so, the third param of WinMain is a LPSTR which will give you the command line as a string ..
Also, you can use the GetCommandLine() API at any point to get this data......
You need some sort of way to tokenise the commandline - so look at strtok from the Std C Library
That is correct. Except that argc will contain number of args + 1, and argv[0] will contain the name of the program.i thought argc held the number of arguments where argv held the arguments ??
The data is in character format, so to extract a number, do:
int first_arg = atoi(argv[1]);
But always remember to check the count in argc, if it is 1, then nothing was entered into the command line, and the program should probably exit gracefully![]()
By the way, the naming convention is arbitrary, you could equally do:
int main(int count, char* array_of_commands[])
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
Code:#include <stdio.h> int main(int argc, char *argv[]) { while (--argc) printf ("%s ", *++argv); return 0; } /* OR */ int main(int argc, char *argv[]) { int i; for (i = 1; i < argc; i++) puts(argv[i]); return 0; }
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]