Document 7291143

Download Report

Transcript Document 7291143

Course Introduction and
Getting Started with C
USF - COP-2270 - C for Engineers
Summer 2008
1
Why C and Matlab?

Why C?

Powerful and portable computer language




Most well known processors be programmed with C
Simple to program
Free!! =D
Why Matlab?


Most powerful programming tool for Engineering
Used in many areas


From Aerospace Industry To Financial companies
No rivals, but expensive
=(
USF - COP-2270 - C for Engineers
Summer 2008
2
Language Classification
High
The Human Language
(e.g. English)
The High-Level
Programming Language
(e.g. C)
Low
The Machine Language
(i.e. binary code)
If the line is not busy,
connect o the Internet,
else, wait…
If (line!= busy)
connect (Internet);
Else
wait (5)…
1000100010100010001110
1111111011101011110101
0111010011…..
Figure adapted from T. Zhang “Teach yourself C in 24 hours”
USF - COP-2270 - C for Engineers
Summer 2008
3
Preparing a program for execution

Steps:

Editing



Compilation
Linking


Create binary code
Loading


Create your source code
Your program is loaded in
memory
Execution

Then is executed
Slide modified from original slides for course offered at University of Arizona: http://www.ece.arizona.edu/~ece175/index.html
USF - COP-2270 - C for Engineers
Summer 2008
4
Getting Started with C
Hour 1
Presentation original from Dr. Turner’s class
USF - COP-2270 - C for Engineers
Summer 2008
5
Objectives
You will be able to:
 Create, compile, and run a very simple C
program on Windows systems and on Unix
systems.
USF - COP-2270 - C for Engineers
Summer 2008
6
Start Up Visual Studio 2005

On classroom and lab computers look for
Microsoft Visual Studio 2005 under
Applications.
USF - COP-2270 - C for Engineers
Summer 2008
7
Start Up Visual Studio 2005
Click
USF - COP-2270 - C for Engineers
Summer 2008
8
Ready to Create a Project
Your screens may be slightly different from the screen shots in this presentation.
USF - COP-2270 - C for Engineers
Summer 2008
9
Creating a C++ Project in Visual Studio 2005
Even though it is called a C++ project, we will write a C program.
USF - COP-2270 - C for Engineers
Summer 2008
10
Creating a C++ Project in Visual Studio 2005
USF - COP-2270 - C for Engineers
Summer 2008
11
Creating a C++ Project in Visual Studio 2005
USF - COP-2270 - C for Engineers
Summer 2008
12
Creating a C++ Project in Visual Studio 2005
USF - COP-2270 - C for Engineers
Summer 2008
13
We Have a Project
USF - COP-2270 - C for Engineers
Summer 2008
14
Adding a Source File to the Project
USF - COP-2270 - C for Engineers
Summer 2008
15
Adding a Source File to the Project
Click
The .c filename extension tells Visual Studio to compile this file
as a C program (not C++).
USF - COP-2270 - C for Engineers
Summer 2008
16
It's Open in the Editor
USF - COP-2270 - C for Engineers
Summer 2008
17
Add the Program Code
USF - COP-2270 - C for Engineers
Summer 2008
18
Compile and Link the Program
USF - COP-2270 - C for Engineers
Summer 2008
19
Run the Program
Click here to run
USF - COP-2270 - C for Engineers
Summer 2008
20
Program "hello.c" in Action
Press "Enter" to end program and close window.
USF - COP-2270 - C for Engineers
Summer 2008
21
Running Without the IDE
Open a Windows Explorer window and navigate to the project directory.
Your directory structure will be different, but you should have a
project directory called “hello” under “Visual Studio 2005\Projects”
USF - COP-2270 - C for Engineers
Summer 2008
22
Running Without Visual Studio
Within the project directory, open the debug folder.
We can double
click here to run
the program
independently of
the IDE.
Here is the exe file.
USF - COP-2270 - C for Engineers
Summer 2008
23
Running Without Visual Studio
USF - COP-2270 - C for Engineers
Summer 2008
24
Running Without Visual Studio





We can also run the program from the
command prompt.
Copy the exe file into a convenient directory
(e.g. C )
Open a command window
cd to the directory
Type the command: hello
USF - COP-2270 - C for Engineers
Summer 2008
25
Running from the Command Line
USF - COP-2270 - C for Engineers
Summer 2008
26
Let's Move the Program to Unix.
Here is our source file.
USF - COP-2270 - C for Engineers
Summer 2008
27
Open an SSH File Transfer Window
Drill down to
C:\Documents and Settings\”username”\My Documents\Visual Studio 2005\Projects\hello\hello
USF - COP-2270 - C for Engineers
Summer 2008
28
Connect to Unix
Click here to connect to sunblast
USF - COP-2270 - C for Engineers
Summer 2008
29
Connecting to sunblast
USF - COP-2270 - C for Engineers
Summer 2008
30
Connecting to sunblast
USF - COP-2270 - C for Engineers
Summer 2008
31
Connecting to sunblast
USF - COP-2270 - C for Engineers
Summer 2008
32
Here we are!
Home directory
on sunblast
USF - COP-2270 - C for Engineers
Summer 2008
33
Pick a Directory
Pick directory to
work in.
USF - COP-2270 - C for Engineers
Summer 2008
34
Copy Source File
Drag source file
into remote
directory window
USF - COP-2270 - C for Engineers
Summer 2008
35
Copy Source File
The file hello.c has been copied from my Windows system to sunblast.
USF - COP-2270 - C for Engineers
Summer 2008
36
Open a Terminal Window
USF - COP-2270 - C for Engineers
Summer 2008
37
Connect to sunblast and cd to test directory.
USF - COP-2270 - C for Engineers
Summer 2008
38
Compile the Program
USF - COP-2270 - C for Engineers
Summer 2008
39
Run It
USF - COP-2270 - C for Engineers
Summer 2008
40
Creating a Source File on sunblast
Delete the files that we have been using. (We will start over!)
USF - COP-2270 - C for Engineers
Summer 2008
41
Creating a Source File on sunblast
USF - COP-2270 - C for Engineers
Summer 2008
42
Editing in pico
USF - COP-2270 - C for Engineers
Summer 2008
43
Editing in pico
USF - COP-2270 - C for Engineers
Summer 2008
44
Write Out the File
Type Control-O to write out the file
Press Enter to name the output file hello.c
USF - COP-2270 - C for Engineers
Summer 2008
45
Exit from pico
Type Control-x to exit from pico
USF - COP-2270 - C for Engineers
Summer 2008
46
Back at the Unix Command Line
USF - COP-2270 - C for Engineers
Summer 2008
47
Compile and Run
USF - COP-2270 - C for Engineers
Summer 2008
48
Assignment

Before next class


If you don't have a College of Engineering
account, get one.
Do the examples from this class for yourself


if you didn’t do them in class.
Read Hour 1 in text

End of Presentation
Note that procedures in the book are different from ours.
USF - COP-2270 - C for Engineers
Summer 2008
49