Learn how to use the Vim Editor for writing C programs and get an introduction to the GCC Compiler. Step-by-step guide for beginners to write, compile, and run C programs efficiently.

Vim Editor, Writing, and Introduction to GCC Compiler

Vim Editor and GCC Compiler are essential tools for writing and compiling C programs, especially in Linux and Unix environments. This guide will help beginners understand how to use Vim for coding, writing C programs, and compiling them with GCC.

  1. Vim Editor in C Programming

Vim is a powerful text editor used in Unix/Linux systems. It is widely used to write C programs because of its lightweight and efficient interface.

Key Features of Vim Editor:

  • Syntax highlighting for C and other programming languages.
  • Efficient editing using keyboard shortcuts.
  • Multiple modes: Normal mode, Insert mode, and Command mode.
  • Lightweight and fast, ideal for coding on servers and low-resource systems.

Basic Vim Commands for C Programming:

  1. Open a file:
  1. vim filename.c
  1. Switch to Insert mode to write code: Press i.
  2. Save and exit:
    • Save changes: Press Esc, then type :w and press Enter.
    • Save and exit: Press Esc, then type :wq and press Enter.
    • Exit without saving: Press Esc, then type :q! and press Enter.
  1. Writing a Simple C Program in Vim

Open Vim and create a file called hello.c:

#include <stdio.h>

int main() {

    printf(“Hello, World!\n”);

    return 0;

}

Steps in Vim:

  1. Open Vim:
  1. vim hello.c
  1. Press i to enter Insert mode.
  2. Type or paste the above code.
  3. Press Esc to return to Normal mode.
  4. Save and exit: :wq
  1. Introduction to GCC Compiler

GCC (GNU Compiler Collection) is used to compile C programs. It converts the human-readable C code into machine-executable files.

Basic GCC Commands:

  1. Compile a C program:
  1. gcc hello.c -o hello
    • hello.c → source file.
    • -o hello → output executable file name.
  1. Run the compiled program:
  1. ./hello

Expected Output:

Hello, World!

  1. Example: Compile and Run a C Program

C Program (addition.c):

#include <stdio.h>

int main() {

    int a, b, sum;

    printf(“Enter first number: “);

    scanf(“%d”, &a);

    printf(“Enter second number: “);

    scanf(“%d”, &b);

    sum = a + b;

    printf(“Sum = %d\n”, sum);

    return 0;

}

Steps to Compile and Run:

  1. Open Vim and create the file:
  1. vim addition.c
  1. Enter Insert mode by pressing i and type/paste the code.
  2. Press Esc and save with :wq.
  3. Compile the code using GCC:
  1. gcc addition.c -o addition
  1. Run the program:
  1. ./addition

Sample Output:

Enter first number: 10

Enter second number: 20

Sum = 30

  1. Advantages of Using Vim and GCC

  • Vim Editor:
    • Lightweight and fast for coding.
    • Supports multiple languages and syntax highlighting.
    • Ideal for terminal-based development.
  • GCC Compiler:
    • Converts C programs into executable files.
    • Supports error checking and debugging.
    • Widely available in Linux, Unix, and Windows (via MinGW).

Conclusion:

Using Vim Editor along with GCC Compiler is an effective way for beginners and professionals to write, compile, and run C programs efficiently. With practice, you can master Vim shortcuts and GCC options for better programming workflow.

Ubunto C Programming

Search- terminal

Ctrl+T – open new terminal

Gcc – version

Prees enter

Sudo apt install build-essential

Clear

Compile: – gcc hello.c – o test

Run: – ./test

Gedit- open notpad

Compile: – gcc – o first first.c

Run: – ./first

Ubunto C++ Programming

g++    – – version

sudo apt install build – essential

open nano – text editor

#include<iostream>

using namespace std;

int main()

{

cout<<”Hello”<<endl;

return 0

}

Save the file – hello.cpp

Compile and run:

g++ hello.cpp –o hello

./hello

OR:

  1. g++ –version (check version)
  2. touch test.cpp (create file)
  3. g++ test.cpp (compile file)
  4. ./o.out (run program)
  5. g++ test.cpp – o
Some More: 

POP- Introduction to Programming Using ‘C’

DS – Data structure Using C

OOP – Object Oriented Programming 

Java Programming

DBMS – Database Management System

RDBMS – Relational Database Management System

Leave a Reply

Your email address will not be published. Required fields are marked *