DCN 3013: Network Programming - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

DCN 3013: Network Programming

Description:

In command mode we can directly go to certain line by typing : linenumber :5 enter ... Exercise. open a new file $ vi hello.c. Once started, vi will be put ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 17
Provided by: notesU
Category:

less

Transcript and Presenter's Notes

Title: DCN 3013: Network Programming


1
DCN 3013 Network Programming
  • Chapter 1 Introduction
  • by
  • Muhammed Ramiza Ramli
  • KUKTEM

2
Overview
  • Introduction to Linux Programming
  • Writing first C code in Linux
  • Using vi editor
  • Using Gnu Common Compiler (gcc) in command prompt
  • Source Code
  • Object Code
  • Loadable modules/Binary file
  • Integrated Development environment Anjuta

3
Linux Environment
  • Linux Desktop

4
Linux Terminal
5
Linux Command
  • ls - list a file/dir
  • ls, ls -a, ls -l, ls -s
  • rm ltfilegt - remove a file
  • rm, rm -Rf
  • cp ltsourcegt ltdistgt - copy a file
  • mv ltsourcegt ltdistgt- move/rename a file
  • mkdir - create a dir
  • rmdir - remove a dir
  • cd ltdistdirgt - change dir into dist dir
  • and a lots more commands and variations of them

6
Output
7
vi Editor
  • most commonly used editor in Linux is vi
  • can be invoked in terminal as below
  • Syntax vi ltfilenamegt
  • vi hello.c

8
vi Editor
  • vi have two input mode
  • command mode
  • edit mode
  • Command mode were used for
  • save, search word, replace character , etc
  • can be switch to by pressing Esc button
  • Edit mode were used to insert or edit data into
    file.
  • can be switch to by pressing several key
  • a append
  • i insert

9
vi command
  • in command mode, we can switch to edit mode to
    start writing by pressing i or a
  • to go to the certain location, we can move the
    cursor by
  • h left, j up, k down, and l right
  • to save a file we must be in command mode and
    using command w
  • w - write
  • q - quit
  • wq - write and quit
  • q! - quit without save
  • w file1 - write as file1

10
vi command
  • Once in edit mode, we can start writing.
  • to save the file switch to command mode by
    pressing Esc.
  • In command mode we can directly go to certain
    line by typing
  • ltlinenumbergt
  • 5 ltentergt
  • To locate a key word typing
  • /keyword
  • cursor will be automatically set on word keyword

11
Exercise
  • open a new file
  • vi hello.c
  • Once started, vi will be put under command mode
  • type i or a to enter the edit mode
  • Write a simple C source program that will display
    Hello World in the screen.
  • Switch to command mode to save it
  • press Esc
  • wq
  • Finish

12
Simple Program
  • include ltstdio.hgt
  • int main()?
  • printf(Hello World!\n)
  • return 0

13
gcc
  • every program written in Linux can be compiled
    by using gcc command
  • gcc syntax
  • gcc ltsourcegt -o ltoutputgt
  • gcc hello.c -o hello
  • invoking gcc without specifying the output file
  • gcc ltsourcegt
  • will produced an output as a.out
  • To produces an object code file.o
  • gcc -c ltsourcegt

14
Run a program
  • Program written in a source form
  • file with .c
  • It can be compiled into an object code
  • file with .o
  • Object code or several object code then can be
    linked in loadable modules or binary file
  • by default a.out
  • any name given by the user
  • To run a program type the program name in the
    command prompt prefix with ./
  • ./program

15
Sample output
16
Using IDE
  • There are two Integrated Development
    Environment commonly used in Linux.
  • Kdevelop Anjuta
Write a Comment
User Comments (0)
About PowerShow.com