How to access argv strings?
I have:
int _tmain(int argc, char* argv[])
{
printf("drive name: %s\n", argv[1]);
It displays only the first character of the first argument on the command line.
Yet the following works as expected:
static char* myArg[2] = {"first arg","second arg"};
printf("drive name: %s\n", myArgv[1]);
That displays the entire string "second arg".
So what's wrong with my reference to argv[1]?
Re: How to access argv strings?
Quote:
Originally Posted by
joeu2004
I have:
int _tmain(int argc, char* argv[])
{
printf("drive name: %s\n", argv[1]);
It displays only the first character of the first argument on the command line.
[....]
So what's wrong with my reference to argv[1]?
Okay....
The original declaration was _TCHAR* argv[], which declares argv[] as pointer to strings of wide chars (wchar_t).
And sure enough, when I revert to that declaration, printf("%ls",argv[1]) displays the entire strings. Note the use of "%ls" instead of "%s".
So I guess my question is: how can I coerce VC++ to pass normal chars (char* argv[]) instead of wide chars?
Probably some kind of build option. If that is the case, I would appreciate click-by-click instructions. I'm a little rusty with using VC++.
Re: How to access argv strings?
Quote:
Originally Posted by
joeu2004
Okay....
The original declaration was _TCHAR* argv[], which declares argv[] as pointer to strings of wide chars (wchar_t).
And sure enough, when I revert to that declaration, printf("%ls",argv[1]) displays the entire strings. Note the use of "%ls" instead of "%s".
So I guess my question is: how can I coerce VC++ to pass normal chars (char* argv[]) instead of wide chars?
Probably some kind of build option. If that is the case, I would appreciate click-by-click instructions. I'm a little rusty with using VC++.
It's in the project properties. Under Configuration Properties/General/Character Set, select Multi-bye character set.
Re: How to access argv strings?
Quote:
Originally Posted by
GCDEF
It's in the project properties. Under Configuration Properties/General/Character Set, select Multi-bye character set.
Great! Thanks. I wanted "Not Set".
Re: How to access argv strings?
To build with any setting:
Code:
int _tmain(int argc, TCHAR* argv[])
{
_tprintf(TEXT("drive name: %s\n"), argv[1]);