使用vi新建CentOS mytest文件学习c语言编程

系统 Linux
"CentOS mytestc.c" 5L, 78C written[OK_008@CentOS4 ~]$ gcc -o CentOS mytestc -g CentOS mytestc.c [OK_008@CentOS4 ~]$ ls --没有任何提示,说明测试通过,使用ls,我们发现目下下多了个编译后的CentOS mytestc文件。

CentOS mytest系统的特性,既可作为高校计算机专业CentOS mytest学习,也可以作为CentOS mytest系统开源爱好者、XX系统用户的学习。今天学习点c语言编程,学习c语言编程时要了解如何编译调式及运行c语言程序。

先使用vi新建一个CentOS mytestc.c文件。

并且输入相关的c程序代码如下操作:[OK_008@CentOS4 ~]$ vi CentOS mytestc.c#include "stdio.h"in main(){printf("Hello,this is my first program.");}"CentOS mytestc.c" [New] 5L, 77C written开始编译。gcc主要时用来编译c/c++程序的。这里只用到gcc的简单参数-o 和 -g。o 表示设定输出文件名。

g 表示加入调式信息,为gdb准备[OK_008@CentOS4 ~]$ gcc -o CentOS mytestc -g CentOS mytestc.cCentOS mytestc.c:2: error: syntax error before "main" 编译错误,提示"main"前面语法错误,这里再使用vi来修改。发现main()前的数据类型int写成了in 比较晕哦,太马虎了。[OK_008@CentOS4 ~]$ vi CentOS mytestc.c#include "stdio.h"int main(){printf("Hello,this is my first program.");}

"CentOS mytestc.c" 5L, 78C written[OK_008@CentOS4 ~]$ gcc -o CentOS mytestc -g CentOS mytestc.c [OK_008@CentOS4 ~]$ ls --没有任何提示,说明测试通过,使用ls,我们发现目下下多了个编译后的CentOS mytestc文件。

debugtest Desktop CentOS mytestc.c mytxt.txt TestFiledebugtest.c  CentOS mytestc  mytxt1.txt OK008Filed untar[OK_008@CentOS4 ~]$ ./CentOS mytestc  --该命令是执行刚才生成的CentOS mytestc文件。Hello,this is my first program.[OK_008@CentOS4 ~]$ --这里是执行结果,ok成功了为了好看,我修改一下程序加个回车。[OK_008@CentOS4 ~]$ vi CentOS mytestc.c

#include "stdio.h"int main(){printf("Hello,this is my first program.\n");}"CentOS mytestc.c" 5L, 80C written [OK_008@CentOS4 ~]$ gcc -o CentOS mytestc -g CentOS mytestc.c 重新编译[OK_008@CentOS4 ~]$ ./CentOS mytestcHello,this is my first program. 成功。[OK_008@CentOS4 ~]$

原来在linux下编译c也不是很难。呵呵,鼓励一下自己,忽悠呀。其实gcc命令中还有很多的参数没有使用。这里也没有使用到gdb调试工具来调式代码,还有可以make和makefile来完成自动维护编译工作,功能不错。到用到的时候再具体了解。

【编辑推荐】

  1. CentOS文件建立目录与使用vi测试
  2. CentOS vsftpd服务器安装与编译配置
  3. 介绍CentOS复制文件以及上机操作
  4. CentOS系统操作下安装相关各种软件
  5. CentOS mail系统安装设置YUM软件
责任编辑:佚名 来源: CSDN
相关推荐

2010-01-11 09:40:02

C++语言

2010-01-15 18:06:58

CentOS文件

2009-08-14 15:54:12

C#编程语言

2011-07-14 22:25:36

2010-01-18 17:14:50

C++语言

2023-04-20 17:26:40

FreeDOSC 语言

2010-02-24 14:38:04

Linux文件

2010-01-15 12:33:32

CentOS连接文件

2015-05-25 15:31:56

C语言学习和使用 C 语言

2010-03-19 09:39:17

Python编程语言

2020-10-19 14:23:48

C语言编程语言

2022-01-13 20:00:16

C语言编程语言

2022-09-24 19:38:40

开源C 语言

2019-08-20 11:11:07

PythonJavaC

2010-08-24 16:07:37

C语言

2023-05-24 09:31:51

CGo

2010-03-05 15:30:29

Android编程语言

2010-03-24 09:20:07

CentOS vi编辑

2017-05-05 09:45:13

编程语言学习代码

2010-07-19 16:47:54

Perl
点赞
收藏

51CTO技术栈公众号