1.vim 创建C程序

  • 使用cd 或者mkdir 选择一个目录存放程序,这里我自己创建的文件为program;
  • 使用cd 进入program后,使用vim 创建一个.test.c 文件
lhy@lhy-PC:~/programfile$ vim test.c
lhy@lhy-PC:~/programfile$ 
  • 然后进入vi编辑器,输入i 开始编辑语言,输入以下程序;

#include<stdio.h>
int main() {
	 printf("hello world!\n");
}
  • 使用按Esc,然后 输入 :wq! ,按enter 进入终端命令

2.C程序运行

  • 对程序进行编译,使用gcc test.c  执行默认生成的可执行程序是a.out,使用./a.out 输出结果;
lhy@lhy-PC:~/programfile$ gcc test.c
lhy@lhy-PC:~/programfile$ ./a.out
hello world!
lhy@lhy-PC:~/programfile$ 

  •  另外一种方法,gcc命令将test.c编译成可执行文件test,如不加-o选项,编译器会把编译后的可执行文件命名为a.out。如下
lhy@lhy-PC:~/programfile$ gcc -o test test.c
lhy@lhy-PC:~/programfile$ ./test 
hello world!

3.常用的操作命令

Linux上vi(vim)编辑器使用教程

 

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐