初学者做 K&R

发布于 2024-07-29 06:35:49 字数 229 浏览 4 评论 0原文

我刚刚开始编程并通过 K&R 来尝试学习 C。我已经读到了有关命令行参数的部分(5.10),但现在我被难住了。 每次我尝试打开用命令行参数编写的程序时,我都会被告知文件 X(X 是参数)不存在。

`gcc -o find find.c

open find test

文件 /Documents/Learning_C/test 不存在。`

有什么建议吗? 谢谢

I'm just starting programming and going through K&R to try and learn C. I've gotten to the section on command line arguments (5.10) but now I'm stumped. Every time I try and open a program I've written with command line arguments I'm told that file X, X being the argument, doesn't exist.

`gcc -o find find.c

open find test

The file /Documents/Learning_C/test does not exist.`

Any suggestions? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小巷里的女流氓 2024-08-05 06:35:49

你用的是什么系统? 在 Unix/Linux 中,你可以编译 & 通过以下方式运行可执行文件:

gcc -o find find.c
./find test

正如其他人指出的,当您的二进制文件前缀为“. /”,不会有任何命名冲突。 但是,如果您在 $PATH 中使 find 可访问,则可能会与 查找test--大多数 *nix 发行版的标准程序...也许您可以选择更具体的名称(即 ./myFind testArg

What system are you on? In Unix/Linux you compile & run your executable via:

gcc -o find find.c
./find test

As others have noted, when you prefix your binary with "./", there wont be any naming conflicts. However, if you made find accessible in your $PATH, you might have some conflicts with find and test--standard programs with most *nix distributions... Maybe you could choose more specific names (i.e. ./myFind testArg)

丶情人眼里出诗心の 2024-08-05 06:35:49

尝试为您的输出可执行文件指定不同的名称。

我怀疑您执行的系统查找命令正在寻找名为“test”的目录。

或者尝试通过执行 Edit: 来强制执行。

./find toto

在命令前添加 ./ 很重要,因为它告诉 shell 在当前目录中执行查找,而不是在 PATH 中执行第一个“查找” 。 通常建议您不要安装 . 出于安全原因,将(当前目录)添加到您的 PATH 中。

HTH

P.S. 忘了说一句关于 K&R 工作的好话。 我在 C 领域工作了三十年后刚刚完成了同样的工作,很高兴能回来并刷新思维!

Try giving your output executable a different name.

I suspect your executing the system find command which is looking for a directory called 'test'.

Or try forcing it by executing

./find toto

Edit: Prepending the ./ to the command is important because it tells the shell to execute the find in the current directory as opposed to the first 'find' that exists in your PATH. It is normally recommended that you don't have . (the current directory) in your PATH for security reasons.

HTH

P.S. Forgot to say good one for working through K&R. I just finished doing the same after working in C for thirty years and it was good to get back and refresh the mind!

哎呦我呸! 2024-08-05 06:35:49

也许您应该粘贴您用于上述插图的程序,而不是让我们所有人单独猜测您到底做错了什么?

Instead of making us all individually guess what exactly you're doing wrong, perhaps you should paste the program you're using for the illustration mentioned ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文