我正在编写我的第一个程序,而且我遇到了直接的障碍。我只是想在屏幕上获得一些简单的文本行,但是当我编译并运行程序时,我得到了:
/用户/ MYNAME /桌面/程序 -bash:/ Users / myname / Desktop / program:权限被拒绝 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;
}
任何想法或反馈都会得到真正的赞赏。提前谢谢。
答案 0 :(得分:4)
这是我在试图让你的简单程序运行时犯错的一个例子。 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