如何在Mac上写第一个C程序

本文资料来源:https://www.youtube.com/watch?v=ov_KAaUkJmA


1.打开termial

 鼠标移动到屏幕右上角,看到一个放大镜,点击它,输入“terminal”, 回车,就可以打开terminal

2.在terminal中输入:cd Desktop  回车

3.在terminla中输入: vi test.c  回车

    这时候会自动跳入到编辑界面,此时点击 i 键就可以编辑了。然后输入你的C程序,比如:

#include <stdio.h>

int main()
{
  printf("hello C on os Mac\n");
  printf("The second line\n");
  return 0; 
}

  

4.书写完你的C程序后,按esc键,然后输入 :wq  回车就将保存好了

5.编译

   在terminal中输入: gcc test.c -o test.o  回车,稍等一会就编译好了

6.运行程序

  在terminal输入: ./test.o  回车 ,就可以与看到程序的运行结果了

猜你喜欢

转载自blog.csdn.net/Johnisjohn/article/details/88767580