c programming language wang jiunn cheng 2003/07/29 [email protected]
Post on 21-Dec-2015
221 views
TRANSCRIPT
C Programming Language
Wang Jiunn Cheng
2003/07/29
http://www.im.usc.edu.tw/wjcheng
References
• Brian W. Kernighan and Dennis M. Ritchie, The C Programming Language, 2/e, Prentice Hall.
• Alice E. Fischer, David W. Eggert, Stephen M. Ross,Applied C: An Introduction and More,McGraw-Hill.
• Stephen Prata,C Primer Plus,4/e, Sams.
Table of Contents
• Introduction
• A Tutorial Introduction• Types, Operators, and Expressions• Control Flow• Functions and Program Structure
• Pointers and Arrays• Structures• Input and Output• The UNIX System Interface
Introduction• Historical Background of Languages
– In 1957, IBM 704 and FORTRAN (the first compiled high-level imperative language)…
– In 1958, MIT AI project and LISP (the first functional programming language)…– In 1958, ALGOL (the greatest influence algorithmic language)…– In 1960, COBOL (the most and oldest widely used language in business computi
ng)…– In 1964, BASIC (the easiest language for beginners to learn and the most popula
r language on microcomputer)…– In 1970, PASCAL (the widely used as a teaching language)…– In 1972, UNIX and C (the most portable system language)…– In 1972, AI and Prolog (a nonprocedural logic programming language)…– In 1980, Smalltalk (the first object-oriented language)…– In 1983, DoD and Ada (the largest design effort language)…– In 1986, C++ (the combining imperative and object-oriented language)…– In 1990, Java (the simplest object-oriented language)…
Introduction
• Historical Background of Computers– The first generation (1946~1954)(the vacuum-tube era)
• In 1944, IBM Mark I (the first electromechanical computer)…• In 1946, ENIAC (the first programmable electronic computer)…• In 1951, UNIVAC (correctly predicts election of US president)…• John von Neumann and EDVAC (the first stored-program computer)
…• MIT Whirlwind I (the first computer with a ferrite-core memory)…
– The second Generation (1955~1964)(the transistor era)• IBM 7094 (the very successfully transistorized commercial
computer)…• ALGOL, COBOL, and FORTRAN…• main memories were replaced by ferrite cores and magnetic
drums…• switching circuits were replaced by transistors…
Introduction• Historical Background of Computers (continued)
– The third generation (1965~1974)(the IC era)• transistor circuits were replaced by integrated circuits…• ferrite-core main memories were replaced by semiconductor memories…• microprogramming technique was widely used in CPU design…• IBM 360 series (mainframe computer of industry standard)…• CDC 6600, 7600, and Cyber series…• ILLIAC IV (a notable supercomputer)…• DEC PDP-5, PDP-8 series (the first commercial minicomputer)…
– The fourth generation (1975~)(the VLSI era)• microporcessors and microcomputers…• In 1975, MIT Altair 8800 (the first microcomputer)…• In 1977, APPLE II (the first well-known personal computer)…• In 1981, IBM PC series…• Motorola 6800 and 68000 series…• Intel 8086/286/386 families…• Intel iPSC (the first personal supercomputer)…
Introduction
• K & R• A general-purpose programming language• A relatively low level language• A system programming language• A machine-independent programming
language• A portable programming language• Closely associated with UNIX system
How to conceive a program?
thinking
compilinglinking
Get a problem assigned by teachers or clients
Conceive a solutionor algorithmto solve this problem
editingcodingWrite
C programs of this task
xxx.cxxx.cpp
xxx.cxxx.cpp
Verify source programs via C compiler
Prune syntax or semantic errors
xxx.oxxx.obj
xxx.oxxx.obj
Correct the program logic
reporting
Print outthe correctresults
Workcomplete!
Create an executable program
xxxxxx.exe
Blue for UNIXBlack for MS Windows
runningdebugging Test
programwith data
Programming Studio
• Hello program– #include line– main() function– printf() function
• Fahrenheit-celsius conversion program– integer variables– arithmetic expressions– while loop– formatted printf()
Programming Studio (cont’d)
• The second version of conversion program– floating point variables– for loop
• The third version of conversion program– #define line
• File coping program– getchar() function– putchar() function– EOF constant– precedence and association of operators
Programming Studio (cont’d)
• Character counting program– prefix and postfix operators– overflow of integer variables– null statement
• Line counting program– if statement– == operator– character constant– ASCII character– newline character
Programming Studio (cont’d)
• Word counting program– if-else statement– || operator
• Character occurrence counting program– integer array– consecutive increasing values of ASCII characters– multi-way decision of if-else statement
Programming Studio (cont’d)
• Power function program– power() function– arguments of function– return value of function– function prototype– call by value
• Finding the longest line program– character array– multiple functions– null character– void return type
Programming Studio (cont’d)
• The second version of finding program– external variable– extern declaration– multiple files
The first problem
• Write a program to print the following words on your console.“Trust me! You can make it! %? #@”
#include <stdio.h>main(){ printf(“Trust me! You can make it! %? #@\n”);}
Vocabulary (1:~)
Blue for C Programming TerminologyBlack for Vocabulary
• Chapter 1: (cont’d)– Approach– Drawback– Extrapolate– Framework– Tutorial– Concise– Precise– Elegant
• 1.1– Hurdle– Leap– Text– Mechanical– Compile– Operating system– File– Botch– Omit– Character– Misspell
• 1.1 (cont’d)– Executable– Statement– Store– Subroutine– Procedure– Perform– Appendix– Communicate– List– Argument– Parentheses– Braces– String– Quote– Sequence– Notation
• 1.1 (cont’d)– Newline– Margin– Error message– Automatically– Identical– Escape sequence– Extensible– Mechanism– Invisible– Tab– Backspace– Double quote– Backslash
• Chapter 1:– Essential– Language– Program– Bog– Precise– Concentrate– Variable– Constant– Arithmetic– Control flow– Function– Rudiment– Intentionally– Exception– Point– Structure– Operator– Statement– Standard– Library
Vocabulary (1.2)• 1.2
– Expression– Formula– Temperature– Equivalent– Comment– Declaration– Loop– Formatted output
– Briefly– Ignore– Blank– Announce– Property– Type– Integer– Floating point– Fractional part– Bit– Quantity
• 1.2 (cont’d)– Significant– Digit– Magnitude– Byte– Double-precision– Object– Array– Structure– Union– Pointer– Assignment– Conversion– Initial– Individual– Semicolon– Indent– Glance– Emphasize– Critical– Recommend
• 1.2 (cont’d)– Passionate– Consistently– Multiply– Divide– Division– Truncate– Discard– Normally– Accessible– Behavior– Conform– Concentrate– Defer– Right-justified– Accurate– Version– Decimal point– Formula– Operand– Explicit
• 1.2 (cont’d)– Width– Specification– Octal– Hexadecimal– Elimination– Limit– Construction– Context
• 1.3– Permissible– Complicated– Evaluate– Initialization– Condition– Increment– Arbitrary– Appropriate– Compact– Reverse
Vocabulary (1.4~)• 1.4
– Observation– Convey– Symbolic– Replacement– Conventionally– Distinguish
• 1.5– Prototype– Model– Stream– Responsibility– Conform– Keyboard– Screen– Interleaved
• 1.5.1– Relational
operator– Bit pattern– Subtle– Valid– Solution– Distinctive– Confused– End of file– Signal– Centralize– Shrink– Idiom– Style– Impenetrable– Curb– Precedence– Absence– Encounter
• 1.5.2– Count– Decrement– Prefix– Postfix– Accumulate– Overflow– Cope– Suppress– Grammatical– Isolate– Null statement– Separate– Intelligently– Boundary
• 1.5.3– Mention– Caution– Occasionally– Legal– Warning– Obvious– Topic– Unambiguous
• 1.5.4– Bare-bone– Literal– Tiny– Clarity– Associate– Guarantee– Truth– Falsehood– Alternative
Vocabulary (1.6~)• 1.6
– Artificial– Illustrate– Aspect– Category– Subscript– Consecutive– Frequently– Advisable– Branch– Histogram– Bar– Horizontal– Vertical– Orientation– Challenge
• 1.7– Encapsulate– Implementation– Exponentiation– Conflict– Return– Environment– Erroneous– Prototype– Parameter– Optional– Documentation– Syntax
• 1.8– Pass– Reference– Temporary– Asset– Liability– Extraneous
• 1.9– Manipulate– Fetch– Sticky– Limit– Brevity– Issue– Revise– Trailing blanks– Remove
• 1.10– Automatic– Invocation– Garbage– External– Globally– Permanently– Storage– Concrete– Allocate– Syntactically– Circumstance– Destroy– Core– Pause– Complexity