传递参数 * 给C程序的凝惑
代码码如下,当给程序传递参数 * 时,发现程序输出 当前目录下的所有文件和文件夹的名称。
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int i = 0;
while(i < argc )
{
puts(argv[i]);
i++;
}
system( "pause ");
}
比如(假设程序名是xxxx): xxxx 11 *
程序输出:
D:\xxxx.exe
11
game
onlinegame
RECYCLER
sysset
System Volume Information
Xunlei
xxxx.cpp
xxxx.exe
未命名1.exe
游戏菜单
请按任意键继续. . .
[解决办法]
楼主不知道*在命令行里代表通配符?
[解决办法]
*/? 是由 shell 解释的 ...
win 的shell功能太弱了 ...
vc6编译的, 如果跑在 bash shell 下也是这个效果 ...
就像这样:
$ cl /nologo 1.c ; ./1 *
1.c
E:\cygwin\home\LL\1.exe
1.c
1.c.bak
1.exe
1.l
1.l.bak
1.l.c