-
December 22nd, 2012, 07:17 PM
#1
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]?
-
December 22nd, 2012, 08:16 PM
#2
Re: How to access argv strings?
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++.
-
December 22nd, 2012, 09:00 PM
#3
Re: How to access argv strings?
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.
-
December 22nd, 2012, 10:31 PM
#4
Re: How to access argv strings?
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".
-
December 24th, 2012, 02:18 AM
#5
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]);
Best regards,
Igor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|