*How to write code and execute programs under Linux
Use of vi
Create a c file
01——vi mode
Use the vi tool to create a c file, enter vi ac in the command line mode , and press the Enter key to enter: the cursor keeps flashing. By default, there is no way to enter code, because the default is the command line mode of vi . Press i to enter . vi input mode:
The appearance of INSERT means entering input mode, and then we can enter the code:
After typing the code, do you need to return to the command line mode from the input mode? Press the ESC key and INSERT will disappear and return to the command line mode.
02——Exit vi and save the code
In command line mode, press: (colon)wq (w: save, q: exit)
You can see that you have exited vi mode
Enter the ls command to list the files under the current file. You can see the c code we created.
Use the gcc compilation tool to compile this C file
Use the gcc compiler to compile C files: gcc ac –o aexe
- c is the name of the c file you want to compile, and aexe is the name of the generated program. Press ls and you can see that the program name aexe turns green, which means it is correct.
Run the program:
./program name (.aexe/)