CS 240 Programming in C Lecturer: Ramin Dehghanpoor Office: S-3-134

Slides:



Advertisements
Similar presentations
Introduction to the Omega Server CSE Overview Intro to Omega Basic Unix Command Files Directories Printing C and C++ compilers GNU Debugger.
Advertisements

Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Dayu Zhang 9/8/2014 Lab02. Example of Commands pwd --- show your current directory This is home of venus, not your home directory Tilde: means you are.
CSCI 1411 FUNDAMENTALS OF COMPUTING LAB Lab Introduction 1 Shane Transue MSCS.
CS 202 Computer Science II Lab Fall 2009 August 27.
CS 202 Computer Science II Lab Fall 2009 September 3.
Course Introduction and Getting Started with C 1 USF - COP C for Engineers Summer 2008.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
A crash course in njit’s Afs
1 CS 240 Programming in C and UNIX Lecturer: Bob Wilson Office: S Phone:
Overview of Linux CS3530 Spring 2014 Dr. José M. Garrido Department of Computer Science.
Help session: Unix basics Keith 9/9/2011. Login in Unix lab  User name: ug0xx Password: ece321 (initial)  The password will not be displayed on the.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Introduction to Shell Script Programming
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction Unix-like system is everywhere Linux Android for smartphones Google Chrome OS for Chromebook Web.
AN INTRO TO UNIX/LINUX COMMANDS BY: JIAYANG WANG.
Vim Editor and Unix Command gcc compiler Computer Networks.
1 Editing a C Program 01/16/15. 2 Objective Use Linux to edit, compile and execute a C program.
CS240 Computer Science II Introduction the Unix File System and File Related Utilities Based on “UNIX for Programmers and Users” by G.Class and K. Ables.
CS 444 Introduction to Operating Systems
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
Basic Unix Commands CGS 3460, Lecture 6 Jan 23, 2006 Zhen Yang.
1May 16, 2005 Week 2 Lab Agenda Command Line FTP Commands Review More UNIX commands to learn File name expansion - * Introduction of vi.
Introduction to Programming Using C An Introduction to Operating Systems.
Week Two Agenda Announcements Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Next lab assignments.
1 Homework Done the reading? –K&R –Glass Chapters 1 and 2 Applied for cs240? (If not, keep at it!) Gotten a UNIX account? (If not, keep at it!)
COP3502: Introduction to Computer Science Yashas Shankar Lecture #2.
More on Using onyx 8/28/13. Program 1 Due a week from today. See website for details.
AN INTRO TO UNIX/LINUX COMMANDS BY: JIAYANG WANG.
1 Introduction to Unix. 2 What is UNIX?  UNIX is an Operating System (OS).  An operating system is a control program that helps the user communicate.
CSE 1320 Basics Dr. Sajib Datta
Dr. Sajib Datta Jan 16,  The website is up.  Course lectures will be uploaded there ◦ Check regularly for assignments and update.
CS 120 Extra: The CS1 Server Tarik Booker CS 120.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Review Why do we use protection levels? Why do we use constructors?
Introduction to C Topics Compilation Using the gcc Compiler
Overview of Linux Fall 2016 Dr. Donghyun Kim
Precept I : Lab Environment, Unix, Bash, Emacs
ENEE150 Discussion 01 Section 0101 Adam Wang.
UNIX To do work for the class, you will be using the Unix operating system. Once connected to the system, you will be presented with a login screen. Once.
SEEM3460 Tutorial Unix Introduction.
First Day in Lab Making a C++ program
Tutorial of Unix Command & shell scriptS 5027
EE516: Embedded Software Project 1
CS1010: Intro Workshop.
Development Environment Basics
Web Programming Essentials:
Prepared by: Eng. Maryam Adel Abdel-Hady
Guide To UNIX Using Linux Third Edition
Introduction to C Topics Compilation Using the gcc Compiler
Welcome to CSCI 230! Problem Solving using C
Assignment Preliminaries
Introduction to C Topics Compilation Using the gcc Compiler
Tutorial of Unix Command & shell scriptS 5027
Tutorial of Unix Command & shell scriptS 5027
Using Linux Commands Lab 3.
Intro to UNIX System and Homework 1
C Programming Lecture Series
CS 444 Introduction to Operating Systems
Web Programming Essentials:
Tutorial of Unix Command & shell scriptS 5027
A Brief Overview of Unix
Introduction to C Topics Compilation Using the gcc Compiler
Introduction Paul Flynn
CS 444 Introduction to Operating Systems
Introduction to C Topics Compilation Using the gcc Compiler
CSCE 206 Lab Structured Programming in C
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to Linux and Code Editing
Presentation transcript:

CS 240 Programming in C Lecturer: Ramin Dehghanpoor Office: S-3-134 Email: ramin.dehghanpoor001@umb.edu Course: https://www.cs.umb.edu/~ramin/cs240 I got help from and used Dr. Cheung’s and Dr. Liang’s slides

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/LINUX File System and File Access

Motivation C is the language of choice for systems programming and embedded systems and it is the mother of all languages. According to the May 2018 Tiobe Programming Community Index (rate language popularity) Mastery of the material in this course may enable you to get a high paying job!

Introduction Syllabus, Lecture Notes and Schedule Required Textbooks Web: http://www.cs.umb.edu/~ramin/cs240/ Required Textbooks The C Programming Language, 2nd Ed., Kernighan & Ritchie LINUX for Programmers and Users, 1st Ed., Glass & Ables

Introduction HW assignments Homework is an Individual Effort Assignment write-ups will be on my website But HW must be done on our UNIX/LINUX systems! Must adhere to the C coding standard http://www.cs.umb.edu/~ramin/cs240/C Coding Guidelines.pdf Homework is 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! If I discover any cheating, I’ll follow school policy!

Introduction to Grading HW assignments (40%) 7 homework (The highest 6 are counted) Exams (60%) 3 exams (The highest two are counted)

Getting Started UNIX Account Apply for a CS240 account in person: see operators in UNIX/PC Lab (S-3-157) or remotely: see instructions posted in http://www.cs.umb.edu/sp/resources/other/faqs/#FAQ02 Access to UNIX systems using PCs in the UNIX/PC Lab or 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

Getting Started Putty SSH Communications http://www.chiark.greenend.org.uk/~sgtatham/putty/ Download, UnZIP and Execute Installer as directed Use Putty configured for SSH2 instead of TELNET Use PSCP or PSFTP or FileZilla for secure ftp SSH Communications Information: http://www.ssh.com/products/ Download from: http://www.cs.umb.edu/~bobw/CS110/SSHSecureShellClient-3.2.9.exe Download and Execute Installer as directed

Getting Started You may want to use your own PC as a “front end” to our UNIX systems This is the way modern SW development environments in industry are set up now Possible using the SSH Communications secure access software package Have four windows open on your PC

Getting Started Four windows: Window to local file folder for your source files Notepad to edit/save a text source file locally SSH Secure File Transfer (or FileZilla) to transfer the locally stored source file to the UNIX/LINUX system SSH Secure Shell to run UNIX/LINUX commands You are on your own to try this on your own PC! Don’t send problem reports to “operator” for help!

Getting Started (Mac and Linux) Mac and Linux operating systems come built-in with terminal programs which offer a command line. Use ssh command. Ssh username@hostname Example: ssh ramin@users.cs.umb.edu

Communication You must send me an email indicating your preferred email address for announcements and lecture schedules. I will communicate with you by that email. Monitor the course website.

C Programming You will learn to write, execute, and debug C language programs in this course We will spend most of the time in class on the C language, MAKE, and the debugger This is the primary material for exams Use Kernighan and Ritchie (K&R) textbook

UNIX/LINUX 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 will be held accountable for UNIX on exams Use the Glass and Ables textbook Also refer to the Basic UNIX Guide posted on the website: http://www.cs.umb.edu/~ghoffman/linux/unix_cs_students.html

Basic UNIX Commands 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 ln creates a new link to a file ls list files in a directory 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 you’re in) rm remove (delete) a file rmdir remove (delete) a directory CTRL-c “Control” key and “c” key together – stop current command

UNIX File System Directory cd cs240 cd .. pwd Sub-directory ls ~$ pwd  print working directory /home/ramin ~$ ls  list what is in there cs240 ~$ cd cs240  go to subdirectory ~/cs240$ ls  list what is in there test.c cd cs240 cd .. pwd Sub-directory ls Sub-directory File rm filename File mkdir New Sub-directory

Hidden Files There are hidden files on your home directory not normally displayed by ls Names of these files begin with ‘.’, e.g. .login You can see them if you use ls with –A option blade64(3)% ls -A .cshrc .plan cs240.f02 mbox private_stuff .login cs105 cs240.old playpen public_html .msgsrc cs240 cs241 playpen2 student .cshrc is a script file executed when shell is started .login file is a script file executed at time of login

UNIX/LINUX File Permissions ramin@itserver6:~$ ls –la drwxr-x--- 2 ramin phd 4096 May 26 19:16 cs240 r =read w =write x =execute - =no access Change file permission using the chmod command: ramin@itserver6:~$ chmod o+rx cs240; ls -la drwxr-xr-x 2 ramin phd 4096 May 26 19:20 cs240 directory User group Others

Home Work Assignment #1: 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 two ways Use a PC in S-3-157, run Putty/SSH and vi or nano Use your home PC, run Putty/SSH and vi or nano Use “gcc” to compile and create a file named “hello” Run “hello” to see the printout on screen Run “script” to create a “typescript” file and run “exit” to end the script file Turn in the “typescript” file for grading

Handing in Assignments Turn in assignments as hard copy of typescript file and also send me your hw files by email before deadline. % script (Start recording typescript file) Script started, file name is typescript % ls –la (list directory entries) % cat hello.c (display source file) % gcc –m32 hello.c –o hello (compile source file in 32-bit mode) % ./hello (run executable file from the current directory) % exit (stop recording) script done on Thu Aug 23 11:30:02 2012 % lpr typescript (print typescript file at the unix lab)

vi or vim Editor (Glass, Pages 82-92) “vi” is a UNIX visual editor (vim is the LINUX version) Keyboard oriented – no use of a mouse! At UNIX prompt, type “vi hello.c” “vi” opens an existing file / creates a new one “vi” has three modes (See next slide) “Command mode” “Insert mode” “Last line command mode”

Last Line Command Mode: “vi” Modes At UNIX prompt, type “vi [filename] ” Type “:” Command Mode: Type commands or move cursor over text Last Line Command Mode: Type “w file” to write file Type “r file” to read file Type “Enter” Type “i” Type “I” Type “a” Type “A” Type “o” Type “O” Type “R” (Glass, p. 58) Type “Esc” Insert Mode: Insert text at the current cursor position Type “q” or “q!” and to exit vi (Return to Unix prompt)

vi’s Text Entry Mode Commands Key Action i Text is inserted in front of the cursor I Text is inserted at the beginning of the current line a Text is added after the cursor A Text is added to the end of the current line o Text is added after the current line O Text is inserted before the current line R Text is replaced (overwritten)

“vi” Commands Movement Commands (Glass, page 86) Up one line “cursor up” or “k” key Down one line “cursor down” or “j” key Right 1 char “cursor right” or “l” key Left 1 char “cursor left” or “h” key Edit commands (Glass, page 87) [n]x delete n characters at cursor [n]dd delete n lines at current line You can find more vi commands in http://www.cs.colostate.edu/helpdocs/vi.html For vi to display line numbers by default, create an .exrc file in your home directory that has the following line: set nu Then save the .exrc file and exit. Logout and log back in. Your new vi session should show line numbers.

hello.c Program(K&R, Page 6) /* hello: first homework assignment name: your name date: xx/xx/xx */ #include <stdio.h> int main(void) { printf(“Hello World!\n”); return 0; } comment C preprocessor directive C function statements

C Program - 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 “*/”. For example: /* This is a multi-line comment int main (void) { printf (“Hello World!\n”); return 0; } /* terminated by this -> */ int main(void) and return is required.

C Source - #include … Because this program uses the Standard I/O Library, it needs to include <stdio.h> 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 the “printf” function without the “#include <stdio.h>”

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

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

Character Constants New line \n backlash \\ Horizontal tab \t question mark \? Vertical tab \v single quote \’ Backspace \b double quote \” Carriage ret \r octal number \ooo Form feed \f hex number \xhh Audible alert \a For example: \n = \12 = \x0A = newline character