gpt4 book ai didi

c - Bash 返回简单 C 程序的权限被拒绝

转载 作者:太空宇宙 更新时间:2023-11-04 01:30:21 24 4
gpt4 key购买 nike

我正在编写我的第一个程序,但立即遇到了障碍。我只是想在屏幕上显示一些简单的文本行,但是当我编译并运行程序时,我得到:

/Users/myname/Desktop/program -bash: /Users/myname/Desktop/program: Permission denied name-mbp:~ myname$

我使用的是 Mac,对命令行不是很熟悉。我做错了什么吗?这是程序:

/* Prints a message on the screen */
#include <stdio.h>
main ()
{

printf("Just one small step for coders. One giant leap for") ;
printf(" programmers!\n") ;
return 0;

}

如有任何想法或反馈,我们将不胜感激。提前致谢。

最佳答案

这是我在尝试让您的简单程序运行时犯错误的一个例子。 Shell 提示以 $ 开头,我的注释以 # 开头,读起来像注释:

$ cat step.c
/* Prints a message on the screen */
#include <stdio.h>
main ()
{
printf("Just one small step for coders. One giant leap for") ;
printf(" programmers!\n") ;
return 0;
}
$ gcc -Wall step.c
step.c:3:1: warning: return type defaults to ‘int’ [-Wreturn-type]
main ()
^
# running gcc with -Wall turns on all warnings
# there is a warning on line 3, but it is tolerable
$ ls step
ls: cannot access step: No such file or directory
# gcc does not make a binary named after the source file
$ ls -l a.out
-rwxrwxr-x 1 msw msw 8562 May 22 03:50 a.out
# it does make a binary file called a.out which is executable (x)
$ a.out
a.out: command not found
# oops, the current directory is not in my path so the shell doesn't
# look here for executables
$ ./a.out
Just one small step for coders. One giant leap for programmers!
# but if I tell it to look in my current directory, it does
$ gcc -o step step.c
#what does gcc do if I tell it the binary should be named "step"?
$ ls -l step
-rwxrwxr-x 1 msw msw 8562 May 22 03:51 step
# it makes a bnary called "step"
$ ./step
Just one small step for coders. One giant leap for programmers!
# which I can run

关于c - Bash 返回简单 C 程序的权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23796926/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com