I am studying how to utilize argc and argv[] parameters to program a convenience UI in Command windows in WIN8.1 x64 system. Here's my source code in VS2013 c++:
int _tmain(_In_ int argc, _In_reads_(argc) char* argv[])
{
PCHAR parm;
printf("argc in main is %d\n", argc);
for (int i = 0; i < argc; i++){
parm = argv[i];
printf("&argv[%d] = %x\n", i, &argv[i]);
printf("argv[%d] = %x\n", i, argv[i]);
printf("*argv[%d] = %c\n", i, *argv[i]);
printf("parm[0] = %c, parm[1] = %c, parm[2] = %c \n", parm[0], parm[1], parm[2]);
}
return 0;
}
Let's assume the exe file is test.exe. While I type in
"test.exe /a"
in command window, I can get argc = 2. When I want to print out the valued stored in argv[], the weird thing happened. Supposedly I should get the output like the following:
&argv[0] = b76148
argv[0] = b76154
*argv[0] = t
parm[0] = t, parm[1] = e, parm[2] = s
// first 3 CHAR of test.exe
&argv[0] = b7614c
argv[0] = b76184
*argv[0] = /
parm[0] = /, parm[1] = a, parm[2] =
// first 3 CHAR of /a
However, I get the following in actual:
&argv[0] = b76148
argv[0] = b76154
*argv[0] = t
parm[0] = t, parm[1] = , parm[2] = e
&argv[0] = b7614c
argv[0] = b76184
*argv[0] = /
parm[0] = /, parm[1] = , parm[2] = a
Because parm is a PCHAR, supposedly I can print out the characters stored in agrv[] one by one, but why parm[1] always be zeros and parm[2] is the CHAR next to parm[0]. I guess it is a memory size issue, but while sizeof(CHAR)=1, I can't figure out why the memory location of 1st CHAR is 2 bytes away from 2nd CHAR.
Thanks for the patient to view this question & I appreciate your help to tell me why I am wrong. Thanks all!