int main(void) { prin...">

How to run C program on Mac OS X using terminal?

I am new to C. Here is my "Hello world!". Program.

#include <stdio.h>

int main(void)    
{
  printf("Hello, world!\n");
  return 0;
}

After I try to run it using the terminal, it says:

MacBook-Pro-MacBook:~ macbook$ /Users/macbook/Desktop/peng/Untitled1
-bash: /Users/macbook/Desktop/peng/Untitled1: Permission denied
MacBook-Pro-MacBook:~ macbook$ 

Why?

+41
source share
7 answers

First save your program as program.c.

Now you need a compiler, so you need to go to the App Store and install Xcode , which is the Apple compiler and development tools. How to find the App Store ? Do a "Spotlight Search" by typing Spaceand start typing App Storeand click Enterwhen it guesses correctly.

App Store :

enter image description here

Xcode : App Store:

enter image description here

Terminal. Terminal? "Spotlight Search", , Space Terminal Enter, Terminal.

:

xcode-select --install

, gcc, , , Xcode:

gcc -Wall -o program program.c

. OS X clang gcc, :

clang program.c -o program

:

./program
Hello, world!

- ++, , , :

clang++ -o program program.cpp
g++ -std=c++11 -o program program.cpp
g++-7 -std=c++11 -o program program.cpp
+83

, :

#include <stdio.h>

int main(void) {
   printf("Hello, world!\n"); //printf instead of pintf
   return 0;
}

HelloWorld.c :

gcc -o HelloWorld HelloWorld.c

:

./HelloWorld

Hello World!

+24

"C-" . "" , . compiler.

, ( "?" ) , , , ( , , script, .)

+4

c- macos

cd , c-
,
make filename

./

+1

:

  • : nano; , . . - .

  • C

  • control(^) + x → , .

  • , y,

  • ; helloStack.c ( .c)

  • , gcc helloStack.c

  • then ./a.out: !
0

1) GCC Mac (Google )

2) , C

3)

, ProgramC Document

   then type this in Terminal
    cd Document
    cd ProgramC

4) , , C ( Hello.c)

5)

   make Hello
   ./hello
-2

(Untitled1).

chmod a+x Untitiled1
-6

All Articles