0% found this document useful (0 votes)
5 views5 pages

Linux Programming Basics and C Functions

The document outlines the first week of a programming course, focusing on familiarizing students with the Linux programming environment and basic programming concepts using C. It covers essential Linux components, popular text editors like Vi, Vim, Emacs, and Nano, and introduces the Turbo C and GCC compilers. Additionally, it explains the usage of printf() and scanf() functions for output and input in C programming, providing syntax and examples for each.

Uploaded by

kanurisubbarao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Linux Programming Basics and C Functions

The document outlines the first week of a programming course, focusing on familiarizing students with the Linux programming environment and basic programming concepts using C. It covers essential Linux components, popular text editors like Vi, Vim, Emacs, and Nano, and introduces the Turbo C and GCC compilers. Additionally, it explains the usage of printf() and scanf() functions for output and input in C programming, providing syntax and examples for each.

Uploaded by

kanurisubbarao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

UNIT I

WEEK 1
Objective: Getting familiar with the programming environment on the computer and writing
the first program.
Suggested Experiments/Activities:
Tutorial 1: Problem-solving using Computers.
Lab1: Familiarization with programming environment
i) Basic Linux environment and its editors like Vi, Vim & Emacs etc.
ii) Exposure to Turbo C, gcc
iii) Writing simple programs using printf(), scanf()

i) Basic Linux environment and its editors like Vi, Vim & Emacs etc.
In the realm of Linux environments and text editors, there are several key players that
are widely used for various tasks ranging from basic text editing to software development.
Here’s an overview of some of the fundamental aspects:

Linux Environment Basics


Linux is a versatile operating system favored for its stability, security, and open-
source nature. It typically consists of:

 Shell: The command-line interface where you interact with the system. Common
shells include Bash (Bourne Again SHell) and Zsh (Z Shell).

 File System: Linux uses a hierarchical file system starting from the root directory `/`.

 Package Management: Different distributions (like Ubuntu, CentOS, Debian) use


package managers (e.g., `apt` for Debian-based, `yum` or `dnf` for RPM-based) to
install, update, and manage software.

Text Editors
Text editors are crucial tools for editing files directly within the terminal or via a
graphical interface. Here are some popular ones:

[Link] / Vim
 Vi: Vi is a classic text editor that comes pre-installed on most Unix-like systems. It
has two main modes: command mode for navigation and editing commands, and
insert mode for inserting text.

 Vim (Vi Improved): Vim is an enhanced version of Vi with additional features and
improvements, such as syntax highlighting, multiple buffers, plugins, and more
customizable options.

DNRCET Prepared by [Link] Kumar CSE Dept. Page 8


2. Emacs
 Emacs: Emacs is another powerful text editor with extensive customization options
and its own Lisp-based scripting language (Emacs Lisp). It supports multiple modes
(e.g., text editing, programming modes) and can be extended with various packages.

3. Nano
 Nano: Nano is a straightforward and easy-to-use text editor designed for users who
prefer a simpler interface compared to Vi/Vim or Emacs. It provides basic text editing
capabilities with on-screen shortcuts.

Basic Commands (Vi/Vim)

Opening a file: `vi filename` or `vim filename`


Switching to insert mode: Press `i` in Vi/Vim to insert text.
Saving and quitting:
 In command mode: `:w` (save), `:q` (quit), `:wq` (save and quit), `:q!` (force quit
without saving changes).
Navigation: Use arrow keys or `h`, `j`, `k`, `l` for left, down, up, right respectively in Vi/Vim
command mode.
Search and replace: `/searchterm` to search, `:s/searchterm/replacement` to replace first
occurrence, `:%s/searchterm/replacement/g` to replace all occurrences.

Basic Commands (Emacs)

 Opening a file: `emacs filename`


 Saving and quitting:
Ctrl + x, Ctrl + s` to save, `Ctrl + x, Ctrl + c` to quit.
 Navigation: Arrow keys or Emacs-specific navigation (`Ctrl + n`, `Ctrl + p` for next
and previous lines).
 Search and replace: `Ctrl + s` to search forward, `Alt + %` for replace, `Alt + x
replace-string` for replacing all occurrences.

Choosing an Editor

 Vi/Vim: Excellent for efficient text editing, especially once mastered, due to its
ubiquity and powerful features.
 Emacs: Ideal for users who prefer extensive customization and integration with other
tools through its Lisp-based scripting.

These editors have their own learning curves, but mastering any of them can significantly
boost productivity in Linux environments, whether you’re writing scripts, editing
configuration files, or programming.

DNRCET Prepared by [Link] Kumar CSE Dept. Page 9


ii) Exposure to Turbo C, gcc
Turbo C and GCC (GNU Compiler Collection) represents encountering two different
environments for programming in C and C++. Here's a breakdown of each:

Turbo C
Turbo C was a popular Integrated Development Environment (IDE) and compiler for
C and C++ developed by Borland. It was widely used in the MS-DOS era and early Windows
environments. Here are some key points about Turbo C:
 IDE: Turbo C provided a simple and integrated environment where you could write,
edit, compile, and debug C and C++ programs.
 Compiler: It included the Borland Turbo C compiler, which adhered to the older
ANSI C standards (pre-ANSI C89/C90).
 Features: Turbo C offered basic debugging tools, a code editor with syntax
highlighting (though limited compared to modern IDEs), and a straightforward
interface suitable for beginners.
 Legacy: While Turbo C was once very popular, it has largely been superseded by
more modern IDEs and compilers due to its outdated standards compliance and lack
of support for modern operating systems.

GCC (GNU Compiler Collection)


GCC, or GNU Compiler Collection, is a robust compiler suite developed by the GNU
Project. It supports various programming languages, including C, C++, Objective-C, Fortran,
Ada, and others. Here's an overview of GCC:
 Compiler: GCC is a command-line compiler that adheres to modern C and C++
standards (C89/C90, C99, C11, C++98, C++11, C++14, C++17, C++20).
 Features: It provides extensive optimization options, supports multiple platforms
(Linux, macOS, Windows via MinGW), and includes advanced debugging features.
 Usage: GCC is commonly used for compiling applications, libraries, and system
software on Unix-like operating systems (Linux, BSD, macOS) and has widespread
adoption in academic, open-source, and commercial software development.
 Tools: Alongside the compiler, GCC includes tools like `g++` for compiling C++
code, `gdb` for debugging, and `make` for building complex projects.

Choosing Between Turbo C and GCC

 Legacy vs Modern: Turbo C is outdated and primarily of historical interest. It's not
suitable for modern software development due to its limited standards compliance and
lack of support for modern platforms.
 Recommendation: For learning and professional development, GCC (or its
derivatives like Clang) is highly recommended. It provides up-to-date language
support, better optimization, and compatibility with modern operating systems and
hardware.
In summary, while Turbo C was influential in its time, GCC represents the modern standard
for C and C++ development. Understanding GCC and its capabilities is crucial for anyone
serious about programming in C and C++ today, whether for academic, professional, or
personal projects.

DNRCET Prepared by [Link] Kumar CSE Dept. Page 10


iii)Writing simple programs using printf(), scanf()
The printf() function is used to display output and the scanf() function is used to take input
from users.
The printf() and scanf() functions are commonly used functions in C Language. These
functions are inbuilt library functions in header files of C programming.

printf() Function

In C Programming language, the printf() function is used for output.

printf() function can take any number of arguments. First argument must be enclosed within
the double quotes “hello” and every other argument should be separated by comma ( , )
within the double quotes.

Important points about printf():


 printf() function is defined in stdio.h header file. By using this function, we can print
the data or user-defined message on monitor (also called the console).
 printf() can print a different kind of data format on the output string.
 To print on a new line on the screen, we use “\n” in printf() statement.

C language is case sensitive programming language. For example, printf() and scanf() in
lowercase letters treated are different from Printf() and Scanf(). All characters in printf() and
scanf() builtin functions must be in lower case.

Syntax

printf("format specifier",argument_list);

The format string for output can


be %d (integer), %c (character), %s (string), %f (float) %lf (double) and %x (hexadecimal)
variable.

Simple Example of printf() Function


#include<stdio.h>
int main()
{
int num = 450;
// print number
printf("Number is %d \n", num);
return 0;
}
Output:
Number is 450

scanf() Function

The scanf() function is used to read input data from the console.

DNRCET Prepared by [Link] Kumar CSE Dept. Page 11


The scanf() function is builtin function available in the C library. scanf() function can read
character, string, numeric & other data from keyboard in C language.
scanf() reads formatted data from user and assign them in the variables provided the
additional arguments. Additional arguments must point to variables that have the same
datatype as of user input data format.
Syntax
scanf("format specifier",argument_list);

Simple Example of scanf() Function


#include<stdio.h>
int main()
{
int x;
printf("enter the number =");
scanf("%d",&x);
printf("The number is=%d",x);
return 0;
}
Output:
enter the number =10
The number is=10

DNRCET Prepared by [Link] Kumar CSE Dept. Page 12

You might also like