CS 240 Programming in C and UNIX - PowerPoint PPT Presentation

About This Presentation
Title:

CS 240 Programming in C and UNIX

Description:

This course will teach you C Programming. It also covers several other ... http://rsug.itd.umich.edu/software/fugu/ (MAC OS X) 8. Getting Started (Editor) ... – PowerPoint PPT presentation

Number of Views:122
Avg rating:3.0/5.0
Slides: 23
Provided by: bobwi9
Learn more at: https://www.cs.umb.edu
Category:
Tags: unix | fugu | programming

less

Transcript and Presenter's Notes

Title: CS 240 Programming in C and UNIX


1
CS 240Programming in C and UNIX
  • Lecturer Bob Wilson
  • Office S-3-071
  • Phone 617-287-6475
  • Email bobw_at_cs.umb.edu

2
Course Objectives
  • This course will teach you C Programming
  • It also covers several other related topics
  • UNIX Commands
  • Compiler and Debugger
  • MAKE and Makefiles
  • UNIX File System and File Access
  • UNIX Processes and Shells/Shell Scripts

3
Motivation
  • C is the language of choice for systems
    programming and embedded systems
  • Number of Programmers by Language
  • COBOL 3 million
  • Visual Basic 1.5 million
  • C/C 1.1 million
  • Mastery of the material in this course may enable
    you to get a high paying job!

4
Introduction
  • Syllabus and Lecture Notes
  • Web http//www.cs.umb.edu/bobw
  • Required Textbooks
  • The C Programming Language, 2nd Ed., Kernighan
    Ritchie
  • UNIX for Programmers and Users, 2nd Ed., Glass
    Ables

5
Introduction
  • HW assignments
  • Assignment write-ups will be on my website
  • But HW must be done on our UNIX systems!
  • All Homework MUST BE an Individual Effort
  • You can answer questions for each other as long
    as you acknowledge any help that you receive from
    others
  • BUT DONT HAVE OR LET ANYONE ELSE DO YOUR
    HOMEWORK FOR YOU!
  • Dont change the owner, group, or mode on any of
    your homework directories or files!! (NO chown,
    chgrp, chmod!)
  • If I discover any cheating, Ill follow school
    policy!

6
Getting Started
  • Fill out the CS240 Student Survey Form on the web
    page as soon as possible
  • UNIX Account
  • Apply for CS240 ASAP!
  • (Science 3rd Floor UNIX Lab)
  • Use Sun Blades in UNIX Lab
  • Access to UNIX systems from your home PC
  • Secure internet access is required now!
  • Can not use TELNET or FTP for remote access!
  • Must use Secure Shell 2 for remote access
  • Can use Putty or SSH Communications S/W packages

7
Getting Started (SSH 2)
  • Putty (Officially Recommended by Systems Staff)
  • http//www.puttyssh.org (Non Commercial
    Downloads)
  • Download SSHSecureShellClient-3.2.5.exe
  • SSH Communications (Recommended by me)
  • http//www.ssh.com/support/downloads/secureshellwk
  • Download Non-Commercial Version (.exe for
    Windows)
  • Or http//ce.uml.edu/sshwinclient.exe
  • Download and Execute Installer executable
  • Student Recommended
  • http//www.i-tree.org/gpl/ixplorer.htm
    (Windows)
  • http//rsug.itd.umich.edu/software/fugu/ (MAC OS
    X)

8
Getting Started (Editor)
  • Editing source files is a requirement
  • Learn to use a UNIX editor program
  • vi a simple visual editor described in Glass
  • emacs a more complex visual editor that can also
    be used as a complete development shell (also
    described in Glass)
  • pico a simple text editor based on the pine
    email program ( I personally like this one!)

9
Getting Started (Email)
  • Use the UNIX program pine for your email
  • Pine is supported by system staff UNIX mail
    program is not.
  • Type command man pine for pine user
    documentation
  • Type command pine to access email

10
Communication
  • You must monitor course web site and your UNIX
    email account for announcements!!
  • To contact me
  • Office S-3-071
  • Office Hours
  • Posted on my website
  • UNIX finger bobw
  • Email bobw_at_cs.umb.edu
  • Phone/Voice Mail (617) 287-6475 (UMB)
  • or (508) 668-7427 (Home) only if really stuck!

11
Java versus C
  • CS110 (Java) is a prerequisite for CS240!
  • Java and C are both block structured languages
  • Compound statements defined by braces
  • Similar if-else, for/while loops, expressions,
    etc
  • Java is Object-Oriented, C is only procedural
  • Java and C syntaxes look deceptively similar
  • However, many small annoying differences
  • Close but different semantics/syntax can be
    confusing
  • Learn C as a different language not just like
    Java!
  • C99 is a bit closer to Java, but were not using
    it here!

12
Java versus C
  • Java Compiler / Interpreter
  • Java source is compiled to byte code file
    (.class)
  • Byte code file is then interpreted by JVM
  • JVM is written in native machine code
  • Interprets program slower than native machine
    code
  • C Compiler / Linker
  • C source is compiled to object file(s)
  • Object file(s) is/are linked to create an
    executable file
  • Executable file runs as native machine code
  • Executes program faster than interpreting byte
    code file

13
C programming
  • You will be learning to write, execute, and debug
    C language programs in this course
  • We will not be just modifying programs that have
    already been written and debugged!!
  • We will spend most of the time in class on the C
    language, MAKE, and the debugger
  • This is the primary material for tests/quizzes
  • Use Kernighan and Ritchie (KR) textbook!!

14
UNIX Operating System
  • You will be using UNIX to edit, compile, debug,
    and run your C programs.
  • We will not spend as much time in class on UNIX.
  • You must learn to use UNIX as you go
  • You can be held accountable for UNIX on exams
  • Use UNIX Guide and Glass textbook
  • Also can refer to the Umass Boston Website
  • http//www.cs.umb.edu/helproot/cs.guide/csguide/cs
    guide.html

15
Basic UNIX Commands(Responsible for these next
time)
  • cat display a file on your terminal screen (see
    also more)
  • cd change directory
  • cp copy a file
  • logout logout from your account
  • lpr print a hard copy
  • ls list files in a directory
  • man xxx manual page for command xxx
  • more display a file on your terminal screen - one
    page at a time
  • mv move a file from one place to another
  • mkdir create a new subdirectory
  • pwd print working directory (pathname of
    directory youre in)
  • rm remove (delete) a file
  • rmdir remove (delete) a directory
  • CTRL-c Control key and c key together stop
    current command

16
UNIX File System
Directory
bobw
cd cs240
cd ..
Sub-directory
bobw/cs240
pwd
ls
bobw/cs240/hw0
Sub-directory
File
bobw/cs240/hw0/assignment
File
rm filename
New Sub-directory
mkdir
17
Hello World!
  • Your first homework project is to create and run
    a C program Hello World! (KR, p5)
  • Create a source file hello.c in one of three
    ways
  • Use Unix Systems in UNIX Lab with vi, pico, or
    emacs
  • Use Putty/SSH on PC to access UNIX with vi, pico,
    or emacs
  • Use Notepad on your own PC and transfer the file
  • Use gcc to compile and create a file named
    hello
  • Run hello to see the printout on screen
  • Use a typescript file to turn in assignments

18
hello.c (KR, Page 6)
  • / hello.c first homework assignment
  • name your name
  • date xx/xx/xx
  • /
  • include ltstdio.hgt
  • int main( ) / well ignore arguments to main
    for now /
  • printf(Hello World!\n)
  • return 0

19
C Source - Comment Lines
  • Comment text is ignored by the compiler
  • / This is a multi-line comment.
  • The compiler ignores both lines. /
  • Be sure to include the closing /
  • / This is a multi-line comment
  • int main ( )
  • printf (Hello World!)
  • return 0
  • / terminated by this -gt /

20
C Source - include
  • Because this program uses the Standard I/O
    Library, it needs to include ltstdio.hgt
  • In C programming, a .h file defines
  • Macros (e.g. Names for constants)
  • Prototypes for functions (e.g. printf itself)
  • gcc wont compile hello.c with printf
    function without the include ltstdio.hgt

21
C Source Main Declaration
  • int main ( ) is the function where the UNIX
    system starts execution of your program
  • Your functions code is within braces
  • Braces are usually placed on their own lines
  • function statements are here

22
C Source - printf
  • The Standard I/O Library provides you with a
    function named printf ( )
  • printf ( ) prints argument as text on screen
  • Argument is the text between the parentheses
    (Hello World!\n)
  • \n is a C convention for end of line
  • (For open book tests, remember KR page 193)
  • All C program statements end with a
Write a Comment
User Comments (0)
About PowerShow.com