Article Directory
Preface
Use vi to write a simple C program that displays "Hello, World!", compile it with gcc and observe the compiled result1. Basic tools used
- vi: vi as the default editor for linux/unix
- gcc: gcc as the most authoritative compiler of the C language
Second, the steps
1. First, use vi to write a C language program file, and enter the command line: vi text.c to create a file named "text.c"
The text.c code is as follows:
#include <stdio.h>
int main()
{
printf("hello world!");
return 0;
}
输入完成后按键盘上Esc退出输入模式,输入:wq将缓冲区内的资料写入磁盘中,并离开vi
At this time, the compilation of the text.c file cannot be completed. When using gcc,'gcc' not found, but can be installed with: sudo apt install gcc.
Open a new command window and enter sudo apt install gcc and wait for the download to complete
2. Compiled successfully
After successful compilation, a new a.out file will be generated.
Enter ./a.out and output hello world!