int _tmain(int argc, char** argv)
{
FILE* file1=fopen(argv[1],"r");
FILE* file2=fopen(argv[2],"w");
}
It seems as if only the first letter of the arguments is received... I don't get why!
std::cout<<"Opening "<<strlen(argv[1])<<" and writing to "<<strlen(argv[2])<<std::endl;
outputs 1 and 1 no matter what. (in MSVC 2010)
To pass command line arguments, we typically define main() with two arguments : first argument is the number of command line arguments and second is list of command-line arguments. The value of argc should be non negative. argv(ARGument Vector) is array of character pointers listing all the arguments.
argv[1] indicates the first argument passed to the program, argv[2] the second argument, and so on.
argv[1] is the first command-line argument. The last argument from the command line is argv[argc - 1] , and argv[argc] is always NULL.
Yes, we can give arguments in the main() function. Command line arguments in C are specified after the name of the program in the system's command line, and these argument values are passed on to your program during program execution. The argc and argv are the two arguments that can pass to main function.
It's not char
it's wchar_t
when you are compiling with UNICODE
set.
It is compiled as wmain
. Linker just does not notice that there is a different signature, because it's "export C" function and it's name does not contain its argument types.
So it should be int _tmain(int argc, TCHAR** argv)
Converting to char is tricky and not always correct - Win32 provided function will only translate the current ANSI codepage correctly.
If you want to use UTF-8 in your application internals then you have to look for the converter elsewhere (such as in Boost)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With