2014-05-22 1 views
1

저는 처음으로 프로그램을 작성 중이며 즉각적인로드 블록을 쳤습니다. 난 그냥 화면에서 텍스트의 몇 가지 간단한 라인을 얻기 위해 노력하고있어,하지만 난 컴파일하고 프로그램을 실행할 때 얻을 :Bash 간단한 C 프로그램에 대한 반송 권한이 거부되었습니다.

/사용자/MyName로/데스크탑/프로그램을 -bash를 :/사용자/MyName로/데스크탑/프로그램 : 권한 이름 MBP를 거부 : ~ 내가 Mac을 사용하고, 명령 줄 훨씬 익숙하지 않아도 $

MyName로. 내가 뭘 잘못하고 있니? 다음은 프로그램입니다.

/* 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; 

} 

모든 의견이나 의견은 진심으로 감사드립니다. 미리 감사드립니다.

+4

당신은 프로그램을 컴파일하고 생성 된 바이너리를 실행해야합니다. 프로그램을 컴파일 했습니까? – devnull

+0

답장을 보내 주셔서 감사합니다. 예, 프로그램을 컴파일하고 실행했습니다. 나는 Code : Blocks IDE를 사용하고 있으며, 컴파일과 실행을 별도로하고, 컴파일/실행 기능을 조합하여 사용하려고 시도했다. – user3648858

+0

@WilliamAndrewMontgomery - 죄송합니다. chmod + x a.out에 익숙하지 않아 실행을 확신 할 수 없습니다. – user3648858

답변

4

이것은 간단한 프로그램을 실행하는 데 실수를 저 짓하는 예입니다. 쉘 프롬프트는 $로 시작하고 내 해설 #로 시작하고 해설을 같이 읽

$ 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 
관련 문제