Professional Documents
Culture Documents
Douglas C. Schmidt
University of California, Irvine
Based on Material Prepared by
Robert C. Carden IV, Ph.D.
Unisys Corporation
Mission Viejo, California
Required textbooks
David R. Brooks, C Programming: The Essentials For Engineers And Scientists,
Springer, New York.
Al Kelley and Ira Pohl, A Book On C, fourth edition, The Addison-Wesley Publishing
Company, Reading, Massachusetts
Gamma, Helm, John, and Vlissides, Design Patterns: Elements of Reusable Software
Components, The Addison-Wesley Publishing Company, Reading, Massachusetts
Recommended textbook
Brian Kernighan and Dennis Ritchie, The C Programming Language, second edition,
Prentice Hall, New Jersey.
Recommended books on the C language
Kamal B. Rojiani, Programming in C with Numerical Methods For Engineers,
Prentice Hall, New Jersey.
A-Series C Manual (Unisys Corporation), reference number 3950 8775-000, New Jersey.
ANSI Draft on the C Programming Language, X3.159-1989
Recommended books covering advanced C language topics
Narain Gehani, An Advanced C Introduction: ANSI C Edition, Computer Science
Press, Rockville, Maryland
Copyright (c) 1998 by Robert C. Carden IV, Ph.D.
10/3/2016
Introduction to Programming in C
1-2
Introduction to Programming in C
Steven R. Lerman, Problem Solving and Computation for Scientists and Engineers:
An Introduction Using C, Prentice Hall, New Jersey
W. Richard Stevens, Advanced Programming in the UNIX Environment, AddisonWesley Publishing Company, Reading, Massachusetts
W. Richard Stevens, UNIX Network Programming, Addison-Wesley Publishing
Company, Reading, Massachusetts
Robert Sedgewick, Algorithms in C, Addison-Wesley Publishing Company, Reading,
Massachusetts
Additional references
Mark Allen Weiss, Data Structures and Algorithm Analysis, The Benjamin/Cummings
Publishing Company, Redwood City, CA
Paul Wang, An Introduction to Berkeley Unix, Wadsworth Publishing Company,
Belmont, CA
Peter A. Darnell, Philip E. Margolis, Software Engineering in C, Springer-Verlag, New
York, NY.
P.J. Plauger, The Standard C Library, Prentice Hall, Englewood Cliffs, NJ
Class Objectives
1-3
Introduction to Programming in C
Attend class
1-4
Introduction to Programming in C
1-5
Introduction to Programming in C
The bottom line is that you will get out of this class
what you put into it!!!
1-6
Introduction to Programming in C
Primary
Storage
Input
Devices
Control
Unit
Arithmetic
Logic Unit
Central Processing
Unit
(CPU)
1-7
Output
Devices
Introduction to Programming in C
1-8
Introduction to Programming in C
2^11
2048
2
4
8
16
32
64
128
256
512
1024
2^12
2^13
2^14
2^15
2^16
2^17
2^18
2^19
2^20
2^21
4096
8192
16,384
32,768
65,536
131,072
263,144
524,288
1,048,576
2,097,152
1K
2K
4K
8K
16K
32K
64K
128K
256K
512K
1M
2M
1-9
Introduction to Programming in C
1011000111000101
Break this up into groups of 4:
1011
0001
1100
0101
11
12
B1C3
=
=
=
=
=
=
A
B
C
D
E
F
=
=
=
=
=
=
10
11
12
13
14
15
=
=
=
=
=
=
1010
1011
1100
1101
1110
1111
By the same token, the HEX number 3F2C1596 represents the binary string:
1-10
Introduction to Programming in C
1-11
Introduction to Programming in C
1-12
Introduction to Programming in C
Compiler
Assemble
r
1-13
Object
Code
Introduction to Programming in C
Language Taxonomy
FORTRAN
COBOL
ALGOL
ASSEMBLER
PL/1
FORTRAN IV
B,BCPL
BURROUGHS
EXTENDED
ALGOL
FORTRAN77
SMALLTALK
APL
ALGOL68
COBOL85
PROLOG
LISP
C
PASCAL
ANSI C
C++
MODULA-2
ADA
1-14
Introduction to Programming in C
History of C
1970'S
Early 1980's
Late 1980's
TRADITIONAL C
ANSI C
[OR STANDARD C]
Add void *
function prototypes
new function definition syntax
minimum standard library
more functionality to preprocessor
Add const and volatile
American
National
Standards
Institute
X3J11 Committee
1-15
Introduction to Programming in C
1-16
Introduction to Programming in C
C++
A less permissive, yet open minded parent (e.g., Thomas Huxtable ;-))
Assumes that the programmer generally knows what he/she is doing, but provides
more checking by default. (With C++ its harder to shoot yourself in the foot, but
when you do, youll blow off both of your legs Bjarne Stroustrup)
A bright red 2000 Corvette with a 6 speed manual transmission, air bag, and heads
up display, many on board computers
1-17
Introduction to Programming in C
Example C Program
/*
File: hello.c
Description: Prints a greeting to stdout.
Author: Douglas C. Schmidt <schmidt@uci.edu>
*/
#include <stdio.h>
int main (void) /* execution starts in main */
{
printf ("Hello world.\n");
return 0;
}
1-18
Introduction to Programming in C
Compiling a C Program
On a personal computer using Visual Studio, you will create a .c file, e.g. hello.c (as in
the previous example). You will then compile it to produce a .exe file (e.g., hello.exe)
and perhaps a .obj file (hello.obj). Consult your compiler documentation (each one is
different).
1-19
Introduction to Programming in C
In Visual Studio, do a File|New and you will see the following dialog...
1-20
Introduction to Programming in C
Here, you must first select Win32 Console Application. Then press the ... button that
appears to the right of the Location
1-21
Introduction to Programming in C
Now choose the location. You may need to create a folder on your file system. In this
case, I brought up the Windows NT explorer and created the new folder Ece11-s98.
Whatever you do, you should place the project in a place such that you can easily find
it later.
1-22
Introduction to Programming in C
Now that you have specified a Location, i.e. a folder where you want your project
created, you should see the following...
1-23
Introduction to Programming in C
Now, specify the name of your project. Visual Studio will create a folder underneath
the one you specified for Location by that name. This will also become the name of
your executable... Finally, click on the OK button to record your selection.
It is very important that you do each of these initial steps in the exact order that I have
described above. That is, first specify that you want a Console Application, then
specify the location, then specify the project name. Do not forget any of these steps.
In other words, pay attention!!!
1-24
Introduction to Programming in C
1-25
Introduction to Programming in C
After selecting the FileView tab, you should see the following. Notice what appears
in the Workspace window...
1-26
Introduction to Programming in C
Now we need to create a source file and include it in the project. If we do the correct
sequence of steps, Visual Studio will automatically include the new file into the
project.
Do a File|New and select Text File and then specify a File name. Do not accept the
default choice, Active Server Page (or whatever happens to be the default). Do not
select C/C++ Header File. Do not select C++ Source File. Select Text File. Do not
forget to type in the file name, i.e. hello.c (or whatever you wish to call it), but it
must end with .c !!! The file suffix tells Visual Studio what type of file this is so it
knows which compiler to invoke on it. Finally, click OK to select your choice.
1-27
Introduction to Programming in C
1-28
Introduction to Programming in C
I usually move the windows around at this point, adjusting the sizes.
Type in the program.
1-29
Introduction to Programming in C
If you click on the + by Hello files under Workspace, you will see a list of all of the
files in your project
Build your program by selecting the Build|Build menu option
1-30
Introduction to Programming in C
1-31
Introduction to Programming in C
1-32
Introduction to Programming in C
1-33
Introduction to Programming in C
foo.s
as -- assembler
foo.o
1-34
Introduction to Programming in C
1-35