Lab 1 Introduction to UNIX and C

Similar documents
Lab 1 Introduction to UNIX and C

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

Intermediate Programming, Spring Misha Kazhdan

CSC111 Computer Science II

LAB #5 Intro to Linux and Python on ENGR

Getting started with UNIX/Linux for G51PRG and G51CSA

CMSC 201 Spring 2018 Lab 01 Hello World

CS CS Tutorial 2 2 Winter 2018

CMSC 201 Spring 2017 Lab 01 Hello World

CMSC 104 Lecture 2 by S Lupoli adapted by C Grasso

CpSc 1111 Lab 1 Introduction to Unix Systems, Editors, and C

Programming Studio #1 ECE 190

Beyond this course. Machine code. Readings: CP:AMA 2.1, 15.4

last time in cs recitations. computer commands. today s topics.

Introduction to Linux Environment. Yun-Wen Chen

Intro to HPC Exercise

User Guide Version 2.0

Laboratory 1 Semester 1 11/12

AMS 200: Working on Linux/Unix Machines

Parallel Programming Pre-Assignment. Setting up the Software Environment

COMP s1 Lecture 1

Saint Louis University. Intro to Linux and C. CSCI 2400/ ECE 3217: Computer Architecture. Instructors: David Ferry

1. The Mac Environment in Sierra Hall 1242

Introduction to Linux. Fundamentals of Computer Science

9 and 11-Jan CSCI 4152/6509 Natural Language Processing Lab 1: FCS Computing Environment, SVN Tutorial. FCS Computing Environment, SVN Tutorial

CSE 351. Introduction & Course Tools

CS 261 Recitation 1 Compiling C on UNIX

CS 2400 Laboratory Assignment #1: Exercises in Compilation and the UNIX Programming Environment (100 pts.)

Session 1: Accessing MUGrid and Command Line Basics

Tutorial 1: Unix Basics

Once you have installed MobaXterm, open MobaXterm. Go to Sessions -> New Session, and click on the SSH icon.

Linux Tutorial #1. Introduction. Login to a remote Linux machine. Using vim to create and edit C++ programs

Introduction: The Unix shell and C programming

15-122: Principles of Imperative Computation

CS Operating Systems, Fall 2018 Project #0 Description

You should see something like this, called the prompt :

Warm-up sheet: Programming in C

Programming Studio #1 ECE 190

Introduction: What is Unix?

1. The Mac Environment in SIE 1222

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

Practical Session 0 Introduction to Linux

Exercise 1: Basic Tools

CSC116: Introduction to Computing - Java

Helpful Tips for Labs. CS140, Spring 2015

Introduction. Overview of 201 Lab and Linux Tutorials. Stef Nychka. September 10, Department of Computing Science University of Alberta

Working With Unix. Scott A. Handley* September 15, *Adapted from UNIX introduction material created by Dr. Julian Catchen

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

Lab 1: Introduction to C, ASCII ART & the Linux Command Line

The Command Shell. Fundamentals of Computer Science

27-Sep CSCI 2132 Software Development Lab 4: Exploring bash and C Compilation. Faculty of Computer Science, Dalhousie University

Lecture 1. A. Sahu and S. V. Rao. Indian Institute of Technology Guwahati

Problem Set 1: Unix Commands 1

Basic Unix Commands. CGS 3460, Lecture 6 Jan 23, 2006 Zhen Yang

Introduction to Linux

Introduction to Linux

p1: Fortune 1. Overview 2. Learning Goals 3. Logistics 4. Linux commands

Introduction to the Linux Command Line

Lab 2 Building on Linux

Carnegie Mellon. Linux Boot Camp. Jack, Matthew, Nishad, Stanley 6 Sep 2016

C++ Programming on Linux

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Refresher workshop in programming for polytechnic graduates General Java Program Compilation Guide

1 Getting Started with Linux.

Hand-on Labs for Chapter 1 and Appendix A CSCE 212 Introduction to Computer Architecture, Spring

Getting Started with UNIX

Chapter 1 An Introduction to C++, Unix, SSH and Komodo Edit

EE516: Embedded Software Project 1. Setting Up Environment for Projects

CSE 391 Editing and Moving Files

COSC UNIX. Textbook. Grading Scheme

Using WestGrid from the desktop Oct on Access Grid

CS 460 Linux Tutorial

One of the hardest things you have to do is to keep track of three kinds of commands when writing and running computer programs. Those commands are:

When talking about how to launch commands and other things that is to be typed into the terminal, the following syntax is used:

CpSc 111 Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input

CS4023 Week04 Lab Exercise

Welcome (back) to CS1007!

Computers and Computation. The Modern Computer. The Operating System. The Operating System

Assignment 1: Build Environment

Getting started with Hugs on Linux

CS Lab 1 Linux/Shell Basic commands Introduction. Teaching Assistant Henrique Potter

Linux Bootcamp Fall 2015

Introduction to Linux

sftp - secure file transfer program - how to transfer files to and from nrs-labs

Unit 10. Linux Operating System

Introduction to Algorithms and Programming I Lab. Exercises #1 Solution

This is a combination of a programming assignment and ungraded exercises

Unix Basics. Systems Programming Concepts

CS1600 Lab Assignment 1 Spring 2016 Due: Feb. 2, 2016 POINTS: 10

Introduction in Unix. Linus Torvalds Ken Thompson & Dennis Ritchie

Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12)

Linux/Cygwin Practice Computer Architecture

CSCE 212H, Spring 2008, Matthews Lab Assignment 1: Representation of Integers Assigned: January 17 Due: January 22

CS11002 Programming and Data Structures Spring Introduction

CENG393 Computer Networks Labwork 1

CSC116: Introduction to Computing - Java

CSCI 2132 Software Development. Lecture 3: Unix Shells and Other Basic Concepts

Programming Assignment 2 (PA2) - DraggingEmoji & ShortLongWords

Programming and Data Structure Laboratory (CS13002)

CSE 391 Lecture 3. bash shell continued: processes; multi-user systems; remote login; editors

Transcription:

Name: Lab 1 Introduction to UNIX and C This first lab is meant to be an introduction to computer environments we will be using this term. You must have a Pitt username to complete this lab. The doc is available at /afs/pitt.edu/home/y/u/yuz69/public/449/lab1/lab-1.doc Recitation TA: Yuyu Zhou Email: yuyuzhou@cs.pitt.edu, SENSQ 6148, Recitation time: 12:00-12:50PM, 2:00-2:50PM SENSQ5505 Office hour: Tuesday 10:00-11:59AM, Wednesday 3:00-5:00PM Responsibility: Recitation, lab and quiz grading Grader: Swarupa Vaishampayan Email: SSV12@pitt.edu Responsibility: project grading NOTE: Text in UNIX is case-sensitive. CS449 is different from cs449 is different from Cs449. All filenames of concern in this lab are lowercase. Please follow the instructions as listed in this document. Here are a few common UNIX commands: cd change directory ls list all files in current directory pwd display the current directory mv move or rename a file cp - copy a file gcc compile a c file pico edit a text file Part I In a Windows Lab: 1) To login to the computers, you will need to use an SSH client. The SSH client that we will be using is Putty located under Programs->Internet Tools in the Start Menu

We will connect to the machine (host name) unixs1.cis.pitt.edu. This machine will be used temporarily for the first part of the class. Eventually you will be using thot.cs.pitt.edu. You can also do this from home or anywhere you have an internet connection. For Windows users, you can download PuTTY (linked to from the course website). Linux and Mac users can open a terminal window and use the ssh command. ssh usrename@unixs1.cis.pitt.edu 2) When you login first, you are placed in your home directory. The command ls will list all of the files and directories there. The one we are most concerned with is the private directory. It is special in that only you can access files inside this directory. It will keep your work safe from other people. 3) Let s move into the private directory so we can work there: cd private Changes Directory to the private directory 4) For this class, we ll keep all of our files organized into a cs449 directory. Make it by typing: mkdir cs449 If you want to double check that it worked, type ls to list. 5) We now want to move into the cs449 directory to do our actual work. cd cs449 Part II. 1) While still in the cs449 directory type: mkdir lab1 cd lab1 to make a directory for today s lab. Now type: pico hello.c

pico is a very simple text editor, a lot like Notepad on windows. It is one option for creating and editing code under UNIX/Linux. 2) Type the following text in exactly as it is shown: #include <stdio.h> int main() { printf( Hello World!\n ); return 0; } 3) Save the file by hitting Ctrl + O and then enter. Exit pico by typing Ctrl + X. At the bottom of the pico window, it shows what keys do special things. The ^ means to hold Ctrl while pressing the key 4) Back at the prompt type: gcc o hello hello.c which will make our program. A file named hello will be in the directory if we type ls 5) Run it by typing:./hello Part III: Manual Pages If you ever want to see how a command works or you forget the various options you could use, you can consult the man pages on the command by typing: man COMMAND for example: man ls This will let you scroll through the online help about the ls command. The SPACE BAR will scroll the document one screenful at a time and the ENTER key will move one line at a time. At any time you can quit by pressing q In the space below, explain the purpose of the -S switch (capital S, not lowercase.)

1.) Part IV: Implementing Horner s method Write a C program that implements Horner's method of evaluating a polynomial. The coefficients of the polynomial will be inferred one at a time from the keyboard as digit characters. Download the lab-1.c starter file for the program you must finish. cp /afs/pitt.edu/home/y/u/yuz69/public/449/lab1/lab-1.c./ You are to repeatedly allow the user to enter in a single digit key from the keyboard (stdin) followed by a return. Use scanf("%c",&charvar) or charvar = getc(stdin) to read the entered key from stdin. After reading the digit, call getchar() to eat the CARRIAGE RETURN that gets entered after every digit key. We don't want that CARRIAGE RETURN code to be confused with our digits. After you read and store that digit key into a char variable, you must convert that ascii code to the numeric value of the pressed key. If the user typed in the '5' key, you must convert that ascii value in the char variable to be the number 5 which is the bit pattern 00000101. This is easily done by subtracting the literal char '0' from the variable you stored the keystroke into. Alternatively you can use the atoi() library call. After that is done you must multiply your running total by 10 and add the value of this latest char you just processed. When the user enters a non-digit value from the keyboard, that is the signal to abort the processing. Your program will then print out the final value of the number. When you are done, email your lab-1.c and answer for S switch to yuyuzhou@cs.pitt.edu before next week s recitation; please include your name and pitt username in your email. Extra tip: try input 2147483647 and 2147483648, observe the integer overflow. You don t need to solve integer overflow problem for this lab. Helpful Hints

Keep this sheet as a guide until you get comfortable in UNIX Every time you want to write a program you will do the following after logging into your account: cd private cd cs449 If you want to use vim or emacs instead of pico, that is fine. You may prefer to edit files under a GUI and use sftp to upload files, the choice is yours. Remember: Case matters!