Prerequisite: The installed Linux has vi/vim installed
Writing C code in Linux
-
Step 1: In the Linux desktop, press Ctrl + AIt + T to open the command port terminal
-
Step 2: Enter the command vi demo.c to enter the command line mode of vi and create a C file named "demo.c"
-
Step 3: Enter the command i ( the character of --INSERT-- appears below , indicating that C code can be written)
-
Step 4: Write C code
-
Step 5: Press Esc to exit the input line mode and enter the command line mode (the bottom-- INSERT-- disappears)
-
Step 6: Enter the command : wq to exit and save
-
Step 7: Enter the command ls to check whether the C file is created and saved successfully
-
Step 8: Enter the command gcc demo.c -o demo to compile the demo.c file and generate the executable file demo
-
Step 9: Enter the command ./demo to run the file
Command input sequence
-
Ctrl + AIt + T
-
vi demo.c
-
i
-
write the code
-
Esc
-
:wq
-
ls
-
gcc demo.c -o demo
-
./demo