学习笔记-linux运行简单的C程序
linux运行简单的C程序
linux环境:centos7
环境条件:linux可连接网络
安装必要的运行C程序的文件
1.安装apue.h文件
linux中执行下载命令
wget http://www.apuebook.com/src.3e.tar.gz
2. 解压下载的安装包:
tar xvf src.3e.tar.gz
3.将安装包放到自己创建的某个文件夹下(为了方便管理)
mv src.3e.tar.gz wenjian/
[root@localhost ~]# cd wenjian
[root@localhost wenjian]# ll
total 96
drwxr-xr-x. 27 501 games 4096 Mar 19 2014 apue.3e
-rw-r--r--. 1 root root 92830 Mar 19 2014 src.3e.tar.gz
4、找到 解压包里的 apue.h文件,并把文件拷贝到 /usr/include路径下(C程序一般需要的头文件都可以放在这里)
[root@localhost include]# pwd
/usr/include
[root@localhost include]# find -name "apue.h"
./apue.h
[root@localhost include]#
写一个C程序
这是一个实现查看目录的函数程序(简单实现linux 指令- ls的功能)
1.创建一个程序文件(个人是在root根目录下直接创建的)
[root@localhost ~]# touch hello.c
[root@localhost ~]# vi hello.c
#include "apue.h"
#include <dirent.h>
int
main(int argc,char *argv[])
{
DIR