csci 130 chapter 1. history of c bell telephone laboratories (1972) dennis ritchie (also created...

13
CSCI 130 Chapter 1

Upload: cornelius-wilson

Post on 30-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSCI 130 Chapter 1. History of C Bell Telephone Laboratories (1972) Dennis Ritchie (also created UNIX) A - B - C

CSCI 130

Chapter 1

Page 2: CSCI 130 Chapter 1. History of C Bell Telephone Laboratories (1972) Dennis Ritchie (also created UNIX) A - B - C

History of C

• Bell Telephone Laboratories (1972)

• Dennis Ritchie (also created UNIX)

• A - B - C

Page 3: CSCI 130 Chapter 1. History of C Bell Telephone Laboratories (1972) Dennis Ritchie (also created UNIX) A - B - C

Initially Many Versions

• Incompatibility

• ANSI– American National Standards Institute

• ANSI Standard C

Page 4: CSCI 130 Chapter 1. History of C Bell Telephone Laboratories (1972) Dennis Ritchie (also created UNIX) A - B - C

Advantages of C

• Powerful, Flexible– Operating Systems– Applications software– Compilers

• Popular

• Portable

• Modular (should be written in functions)

Page 5: CSCI 130 Chapter 1. History of C Bell Telephone Laboratories (1972) Dennis Ritchie (also created UNIX) A - B - C

Problem Solving Technique

• Define Problem

• Devise plan to fix problem

• Implement the plan

• Test

Page 6: CSCI 130 Chapter 1. History of C Bell Telephone Laboratories (1972) Dennis Ritchie (also created UNIX) A - B - C

Necessary Information

• Is computer program required?

• Inputs/Outputs

• Formulas

• Organization (flow of logic)

Page 7: CSCI 130 Chapter 1. History of C Bell Telephone Laboratories (1972) Dennis Ritchie (also created UNIX) A - B - C

Ex: Find area of a circle

• Is computer required?

• Inputs / Outputs– Need the radius of circle as input– Area will be the output

• Formulas– Area = pi * radius ^ 2

Page 8: CSCI 130 Chapter 1. History of C Bell Telephone Laboratories (1972) Dennis Ritchie (also created UNIX) A - B - C

Find area of circle - continued

• Flow of logic:– Request radius of circle– Calculate area = pi * radius ^ 2– Output area

Page 9: CSCI 130 Chapter 1. History of C Bell Telephone Laboratories (1972) Dennis Ritchie (also created UNIX) A - B - C

Steps in C programming cycle

• Use editor to create source code

• Compile source code into object code

• Link object file into executable file

• Execute file

Page 10: CSCI 130 Chapter 1. History of C Bell Telephone Laboratories (1972) Dennis Ritchie (also created UNIX) A - B - C

Use editor to create source code

• Any editor can be used– Editor supplied with language

• Any text based editor

• DOS editor

• Notepad

• Write program following syntax of language

• Save file as: filename.c

Page 11: CSCI 130 Chapter 1. History of C Bell Telephone Laboratories (1972) Dennis Ritchie (also created UNIX) A - B - C

Compile Source Code

• Different compilers use different commands

• Most (such as Borland, Code Warrior) have IDE - can compile via GUI interface

• Process creates a new file: filename.obj

• This file is object code - in format readable by machine

Page 12: CSCI 130 Chapter 1. History of C Bell Telephone Laboratories (1972) Dennis Ritchie (also created UNIX) A - B - C

Link object file

• Most compilers will do this via GUI interface as well (may combine compiling and linking)

• Links internal C library functions (such as printf, scanf) with source code

• Creates new file: filename.exe

Page 13: CSCI 130 Chapter 1. History of C Bell Telephone Laboratories (1972) Dennis Ritchie (also created UNIX) A - B - C

Execute Program

• Program can now be executed– Type filename at DOS prompt– Most compilers allow program to be run via

GUI interface• may combine compiling, linking, and running

• Finished product can be shared– source code does not have to be shared