How to write C code in Linux

Prerequisite: The installed Linux has vi/vim installed 

 

Writing C code in Linux

  1. Step 1: In the Linux desktop, press  Ctrl + AIt + T to open the command port terminal

  2. Step 2: Enter the command  vi demo.c to enter the command line mode of vi and create a C file named "demo.c"

  3. Step 3: Enter the command i   ( the character of --INSERT-- appears below , indicating that C code can be written)

  4. Step 4: Write C code

  5. Step 5: Press Esc to exit the input line mode and enter the command line mode (the bottom-- INSERT-- disappears)

  6. Step 6: Enter the command : wq to exit and save

  7. Step 7: Enter the command ls to check whether the C file is created and saved successfully

  8. Step 8: Enter the command gcc demo.c -o demo to  compile the demo.c file and generate the executable file demo

  9. Step 9: Enter the command ./demo to  run the file

 

Command input sequence

  1. Ctrl + AIt + T

  2. vi demo.c

  3. i

  4. write the code

  5. Esc 

  6. :wq

  7. ls

  8. gcc demo.c -o demo

  9. ./demo

Guess you like

Origin blog.csdn.net/weixin_49472648/article/details/108764204