Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CS 240 Programming in C and UNIX Lecturer: Bob Wilson Office: S-3-071 Phone: 617-287-6475

Similar presentations


Presentation on theme: "1 CS 240 Programming in C and UNIX Lecturer: Bob Wilson Office: S-3-071 Phone: 617-287-6475"— Presentation transcript:

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

2 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 3 Motivation C is the language of choice for systems programming and embedded systems Number of Programmers by Language: –COBOL3 million –Visual Basic1.5 million –C/C++1.1 million Mastery of the material in this course may enable you to get a high paying job!

4 4 Introduction Syllabus and Lecture Notes –Web: http://www.cs.umb.edu/~bobwhttp://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 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 DON’T HAVE OR LET ANYONE ELSE DO YOUR HOMEWORK FOR YOU! –Don’t change the owner, group, or mode on any of your homework directories or files!! (NO chown, chgrp, chmod!) –If I discover any cheating, I’ll follow school policy!

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

8 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 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 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@cs.umb.edubobw@cs.umb.edu –Phone/Voice Mail: (617) 287-6475 (UMB) –or (508) 668-7427 (Home) only if really stuck!

11 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 we’re not using it here!

12 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 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 (K&R) textbook!!

14 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/csguide.html

15 15 Basic UNIX Commands (Responsible for these next time) cat display a file on your terminal screen (see also “more”) cdchange directory cpcopy a file logoutlogout from your account lprprint a hard copy lslist files in a directory man xxxmanual page for command xxx moredisplay a file on your terminal screen - one page at a time mvmove a file from one place to another mkdircreate a new subdirectory pwdprint working directory (pathname of directory you’re in) rmremove (delete) a file rmdirremove (delete) a directory CTRL-c“Control” key and “c” key together – stop current command

16 16 UNIX File System Directory Sub-directory File bobw ~bobw/cs240 ~bobw/cs240/hw0 ~bobw/cs240/hw0/assignment ls cd cs240cd.. rm filename New Sub-directory mkdir pwd

17 17 Hello World! Your first homework project is to create and run a C program – “Hello World!” (K&R, 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 18 hello.c (K&R, Page 6) /* hello.c: first homework assignment name: your name date: xx/xx/xx */ #include int main( ) /* we’ll ignore arguments to main for now */ { printf(“Hello World!\n”); return 0; }

19 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 -> */

20 20 C Source - #include … Because this program uses the Standard I/O Library, it needs to include In C programming, a “.h file” defines –Macros (e.g. Names for constants) –Prototypes for functions (e.g. printf itself) “gcc won’t compile “hello.c” with “printf” function without the “#include ”

21 21 C Source – Main Declaration “int main ( )” is the function where the UNIX system starts execution of your program Your function’s code is within “braces” { } Braces are usually placed on their own lines { function statements are here; }

22 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 K&R page 193) All C program statements end with a “;”


Download ppt "1 CS 240 Programming in C and UNIX Lecturer: Bob Wilson Office: S-3-071 Phone: 617-287-6475"

Similar presentations


Ads by Google