1 editing a c program 01/16/15. 2 objective use linux to edit, compile and execute a c program

15
1 Editing a C Program 01/16/15

Upload: evelyn-green

Post on 31-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Editing a C Program 01/16/15. 2 Objective Use Linux to edit, compile and execute a C program

1

Editing a C Program

01/16/15

Page 2: 1 Editing a C Program 01/16/15. 2 Objective Use Linux to edit, compile and execute a C program

2

Objective

• Use Linux to edit, compile and execute a C program

Page 3: 1 Editing a C Program 01/16/15. 2 Objective Use Linux to edit, compile and execute a C program

3

Login and Password• Don’t lose it

• Keep password a secret

Page 4: 1 Editing a C Program 01/16/15. 2 Objective Use Linux to edit, compile and execute a C program

4

Steps to Run a C program

• Login into onyx

• Edit the program using vi or vim

• Compile the program with gcc

• Execute the program with a.out

• Logout out of onyx

Page 5: 1 Editing a C Program 01/16/15. 2 Objective Use Linux to edit, compile and execute a C program

5

What are two modes in vi?

• Command

• Insert

Page 6: 1 Editing a C Program 01/16/15. 2 Objective Use Linux to edit, compile and execute a C program

6

vim• I want to write a program whose output is:Martin Luther King said:

I have a dream.

• I will write a C program to do that.

• I will use the vim editor to create the program.

Page 7: 1 Editing a C Program 01/16/15. 2 Objective Use Linux to edit, compile and execute a C program

7

To Execute a Program

• vim prog.c– Edit the program– Save with :wq

• gcc prog.c– If there are errors, correct and recompile.

• a.out

Page 8: 1 Editing a C Program 01/16/15. 2 Objective Use Linux to edit, compile and execute a C program

8

Logout

• exit

• Right click on desk top

• Select “leave”

• Select “logout” button

• Important

Page 9: 1 Editing a C Program 01/16/15. 2 Objective Use Linux to edit, compile and execute a C program

9

vim Commands• a, i -- Get into insert mode• <esc> -- Get back to command mode• x -- delete a character• dd -- delete a line• p -- paste• u -- undo• :wq -- write and quit• :q! -- quit without saving.• arrow keys -- move around

Page 10: 1 Editing a C Program 01/16/15. 2 Objective Use Linux to edit, compile and execute a C program

10

More vim Commands• 3x -- Number makes command happen that many

times.• p - put (paste) • r – replace• G

• You should know the commands in the vimtutor, 1.1 to 4.1

Page 11: 1 Editing a C Program 01/16/15. 2 Objective Use Linux to edit, compile and execute a C program

11

More Linux

• Command Formatcommand -options arguments

• Commands to know:– ls, lpr, cp , rm, mv, – mkdir, mv(to a directory), cd, cd .., rmdir– man, more, cat– exit

Page 12: 1 Editing a C Program 01/16/15. 2 Objective Use Linux to edit, compile and execute a C program

12

Login from Remote Site

• You can get mobaxterm or other ssh software if you have a PC

• For Macs see me.

Page 13: 1 Editing a C Program 01/16/15. 2 Objective Use Linux to edit, compile and execute a C program

13

Engr 213 & 214

• Labs for Comp Sci.

Page 14: 1 Editing a C Program 01/16/15. 2 Objective Use Linux to edit, compile and execute a C program

14

Assignment

• See the website for assignment.• Do program 1 for next Friday, 1/23/15

Page 15: 1 Editing a C Program 01/16/15. 2 Objective Use Linux to edit, compile and execute a C program

15

Next Week

• Hardware, software and algorithms

• Getting Started in C Programming