簡體   English   中英

簡單的C程序拒絕Bash返回權限

[英]Bash Returning Permission Denied for Simple C Program

我正在編寫我的第一個程序,但遇到了直接障礙。 我只是想在屏幕上獲得一些簡單的文本行,但是當我編譯並運行程序時,我得到了:

/ Users / myname / Desktop / program -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;

}

任何想法或反饋將不勝感激。 提前致謝。

這是我在嘗試使您的簡單程序運行時出錯的一個示例。 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM