如何在Mac下编写C程序

最近在熟悉一些基础的算法实现,很多是用C实现的,在这里简单的介绍一下如何用终端在mac中编写c程序。

1、首先,快捷键command+空格 ,在搜索框中输入terminal(输入ter即可弹出),回车打开终端;

2、打开终端后,进入我的目录路径下,输入命令:

➜  ~ cd /Users/ljf/selfDoc/C
➜  C ll

3、用编辑器写一个c文件,这里用sublime2

#include<stdio.h>
int main(){
        printf("hello\n");
        return 0;
}

4、编译,输入命令gcc helloword.c,此时如果电脑上没有编译工具,点击安装即可;若程序有错误,则再次进入步骤3修改程序;若无错则进入下一步骤;

5、运行,输入./a.out helloworld.c运行出结果。

➜  C gcc helloworld.c
➜  C ./a.out helloworld.c
hello
➜  C

猜你喜欢

转载自blog.csdn.net/u014028063/article/details/81903396