djgpp会自动把*展开成一个个的文件?

ckc 2002-09-10 05:28:13
for (i = 1; i < argc; i++)printf("%s\n",argv[i]);

这一句代码执行的时候比如
test *
它会自动展开,把
test.c
test.o
test.exe
什么的打印出来。太牛了。
不过我如果不想把*展开,也就是说
如果我的参数中确实需要输入*,那该怎么办?
另外 test *. 在dos下无法正确展开
其实dos下 *. 表示所有没有扩展名的文件
这个又该怎么解决?
...全文
26 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lownr 2002-09-13
  • 打赏
  • 举报
回复
DJGPP FAQ
----------------------------------------------------
16.2 How to disable filename wildcards expansion
Q: I don't want my program to glob its arguments (they aren't files at all, but they include characters like * and ?). What should I do?



A: You have these alternatives:

Surround your arguments with single or double quotes (this is what you would do under a Unix shell).
Disable globbing for your program by linking it with your custom version of the function with the special name __crt0_glob_function and make it always return a NULL pointer. See the documentation of this function in the library reference, for more details. Here's an example:
#include <crt0.h>

char **__crt0_glob_function (char *arg)
{
return 0;
}


大意是
1、用单引号,例如'test*'
2、连接自己的定制版 __crt0_glob_function 函数。

#include <crt0.h>

char **__crt0_glob_function (char *arg)
{
// 总是返回NULL
return 0;
}

完整的例子:

#include <crt0.h>
#include <iostream>
using namespace std;

char **__crt0_glob_function (char *arg)
{
// 总是返回NULL
return 0;
}

int main(int argc, char* argv[])
{
for(int i = 0; i < argc; i++)
{
cout << argv[i] << endl;
}

return 0;
}
// 我已经实验过了,是可以的

希望用DJGPP的同志能够添加我的MSN账号 dualface@msn.com,方便大家交流。
ckc 2002-09-11
  • 打赏
  • 举报
回复
那我在dos下执行也是这样的结果啊,难道dos的shell也有自动匹配功能?
而且如果是shell的自动匹配功能,为什么在dos下*.无法匹配?
Hpt370 2002-09-11
  • 打赏
  • 举报
回复
这个不是djgpp的功能,而是shell的自动匹配功能

你在,命令行下面输入 xxx 'test*'就可以不自动匹配了
ckc 2002-09-11
  • 打赏
  • 举报
回复
我问djgpp啊,另外ibm AIX下的cc也是这样的
linux下的gcc也是这样的
gosirius 2002-09-10
  • 打赏
  • 举报
回复
我用的事vc6载win2k下,没有出现你说的那种情况。

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧