91.102 - Computing II - Problem Session - 1. Some Notes on Input/Output. In C++ you used two primary functions to manage console-directed Input and Output.

Slides:



Advertisements
Similar presentations
ARDUINO CLUB Session 1: C & An Introduction to Linux.
Advertisements

CS1010 Programming Methodology
Utilizing the GDB debugger to analyze programs Background and application.
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.
Linux+ Guide to Linux Certification, Second Edition
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
CS1020: Intro Workshop. Topics CS1020Intro Workshop Login to UNIX operating system 2. …………………………………… 3. …………………………………… 4. …………………………………… 5. ……………………………………
Unix Basics. Systems Programming: Unix Basics 2 Unix Basics  Unix directories  Important Unix file commands  File and Directory Access Rights through.
Basic Input/Output and Variables Ethan Cerami New York
UNIX By Darcy Tatlock. 1. Successful Log Into Unix To actively manipulate your website you need to be logged in. Without being logged in you cannot enter.
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
Systems Programming Concepts
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
COMP1070/2002/lec4/H.Melikian COMP1070 Lecture #5  Files and directories in UNIX  Various types of files  File attributes  Notion of pathname  Commands.
Homework Reading Programming Assignments
1 Day 3 Directories Files Moving & Copying. 2 Case Sensitive First thing to learn about UNIX is that everything is case sensitive. Thus the files: –enda.
Chapter 9 Part II Linux Command Line Access to Linux Authenticated login using a Linux account is required to access a Linux system. The Linux prompt will.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
Unix Basics Chapter 4.
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
AN INTRO TO UNIX/LINUX COMMANDS BY: JIAYANG WANG.
Object-Oriented Software Engineering Using UNIX groups and Subversion Estimated Time: minutes “Unix is user-friendly. It's just very selective about.
Object-Oriented Software Engineering Using UNIX groups and CVS Estimated Time: minutes.
FTP Server and FTP Commands By Nanda Ganesan, Ph.D. © Nanda Ganesan, All Rights Reserved.
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
1 計算機程式設計 Introduction to Computer Programming Lecture01: Introduction and Hello World 9/10/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction.
1 INFO 321 Server Technologies II FTP Material adapted from Dr. Randy Kaplan.
Intro. To Unix commands For those who’ve never used Unix before Quick tutorial to let you move around your Unix Accounts No discussion of inner workings.
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
Getting started: Basics Outline: I.Connecting to cluster: ssh II.Connecting outside UCF firewall: VPN client III.Introduction to Linux IV.Intoduction to.
Chapter 3: Formatted Input/Output Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
1 C Programming Week 2 Variables, flow control and the Debugger.
Basic Unix Commands CGS 3460, Lecture 6 Jan 23, 2006 Zhen Yang.
Unix Commands PowerPoint Presentation developed for LS 560 Information Technology online class - University of Alabama by Debey Sklenar TENacious Cohort.
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.
CPS120: Introduction to Computer Science Compiling a C++ Program From The Command Line.
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!)
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Input and Output.
1 Getting Started with C++ Part 2 Linux. 2 Getting Started on Linux Now we will look at Linux. See how to copy files between Windows and Linux Compile.
FTP COMMANDS OBJECTIVES. General overview. Introduction to FTP server. Types of FTP users. FTP commands examples. FTP commands in action (example of use).
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.
 Last lesson, the Windows Operating System was discussed along with the Windows command shell  Unix is a computer operating system, that similarly manages.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
CSE 1320 Basics Dr. Sajib Datta
Online Judge System Tom Chao Zhou CSC2100B Data Structures Tutorial 2.
Intro. To Unix commands For those who’ve never used Unix before Quick tutorial to let you move around your Unix Accounts No discussion of inner workings.
1 CS101 Fall 2001 Lecture 1 In order to write a program, you must first telnet to your pegasus account and login either from a Rutgers computer in a lab,
Chapter 3: Formatted Input/Output 1 Chapter 3 Formatted Input/Output.
Learning Unix/Linux Based on slides from: Eric Bishop.
Object Oriented Programming COP3330 / CGS5409.  Assignment Submission Overview  Compiling with g++  Using Makefiles  Misc. Review.
+ Note On the Use of Different Data Types Use the data type that conserves memory and still accomplishes the desired purpose. For example, depending on.
Linux CSE 1222 CSE1222: Lecture 1BThe Ohio State University1.
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
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.
CS1010: Intro Workshop.
Andy Wang Object Oriented Programming in C++ COP 3330
ECE Application Programming
Input/output.
Getting Started with C.
Programming in C Input / Output.
Input/Output Input/Output operations are performed using input/output functions Common input/output functions are provided as part of C’s standard input/output.
Chapter 08- printf and scanf
Homework Applied for cs240? (If not, keep at it!) 8/10 Done with HW1?
Programs written in C and C++ can run on many different computers
Introduction to C Programming
Presentation transcript:

Computing II - Problem Session - 1. Some Notes on Input/Output. In C++ you used two primary functions to manage console-directed Input and Output. A sample program - similar to one in a C++ text: #include int main() { intinteger1, integer2, sum; // declare vars cout << “Enter first integer\n”;// prompt user cin >> integer1; // read integer cout << “Enter a second integer\n”; cin >> integer2; // read integer sum = integer1 + integer2; // compute sum cout << “Sum is “ << sum << endl;// output result return 0; }

Computing II - Problem Session - 1. How would we say the same in C? #include int main() { intinteger1, integer2, sum; // declare vars printf(“Enter first integer\n”);// prompt user scanf(“%d”, &integer1); // read integer printf(“Enter a second integer\n”); scanf(“%d”, &integer2); // read integer sum = integer1 + integer2; // compute sum printf(“Sum is %d \n”, sum); // output result return 0; }

Computing II - Problem Session - 1. The two pairs of functions are fairly similar. cin and cout don’t seem to require formatting information; while printf and scanf do. The C++ version is easier to use, while the C version allows more flexibility. Let’s look at a couple more examples of what scanf and printf will let you do. You could have #include int main() { intinteger1, integer2, sum; // declare vars printf("Enter two integers separated by a space\n"); scanf("%d %d", &integer1, &integer2);//read integer sum = integer1 + integer2; // compute sum printf("Sum is %d \n", sum); // output result return 0; }

Computing II - Problem Session - 1. #include int main() { intinteger1; float float1, sum; // declare vars char*st="This is it!"; printf("Enter an integer followed by a floating point number;\n"); // prompt user printf("separate them with a space.\n");// prompt user scanf("%d %f", &integer1, &float1);// read int and float sum = integer1 + float1; // compute sum printf("First Printout:\n"); printf("Sum of %d and %f is %f.\n", integer1, float1, sum);// output result printf("Second Printout:\n"); printf("Sum of %8d and %6.2f is %8.4f.\n", integer1, float1, sum);// output result printf("Third Printout: %s.\n", st); printf("Sum of %8d and %10.2f is %10.4f.\n", integer1, float1, sum);// output result return 0; }

Computing II - Problem Session - 1. The console interaction looks like Enter an integer followed by a floating point number; separate them with a space First Printout: Sum of 123 and is Second Printout: Sum of 123 and is Third Printout: This is it!. Sum of 123 and is Notice the formatting and lack thereof - the unformatted stuff even shows some of the problems associated with representation precision.

Computing II - Problem Session - 1. Format Specifiers, after the % character: Zero or more flag characters (-, +, #, 0, ) Optional minimum field width (decimal integer) Optional precision specification (decimal integer) Optional size specification (l, L, or h) Conversion operator - a single character from a rather large set: c - character; d - decimal digit; o - octal digit; X - hexadecimal digit; f - double; s - *char (a string); etc… %-#014.5lf will left justify a (decimal) long double over 14 character position with 5 decimal precision.

Computing II - Problem Session - 1. Some Notes on UNIX. login: password: And then what? You will probably end up in CDE (Common Desktop Environment), which looks quite close to Windows or the Macintosh so that a bit of experimentation will get you to do most of what you need. One of the things you will also need is to open a “console” window that will allow you to execute commands. This console window will allow you to perform housekeeping activities that are somewhat harder to do in the window environment.

ls -l: lists the contents of the directory with size and date and other info. ls -a: will list the “dot” files too (all files) rm : will delete a file rmdir : will delete an empty directory cd : change your current working directory to the named one (you can jump) cd.. : change your current working directory to the one hierarchically just above it Computing II - Problem Session - 1.

When you are bored with the simple commands, man ls, man rm, man rmdir, man cd, Will provide you with all the information you never wanted to know you didn’t know on how to use these commands. Another useful command is chmod. In a multi-user environment you must have some mechanism to allow some users access to your files, while denying access to other users.

Computing II - Problem Session - 1. Here is the syntax(Abrahams): chmod modespecs file Where file is a given file name and modespecs is either a comma-separated list of permission changes or an octal number of up to four digits. Each permission has 3 parts: one or more ‘who’ letters, an operator, and one or more permission letters.

Computing II - Problem Session - 1. The who letters: u - permission for the file’s user; g - permission for the file’s group; o - permission for others (= rest of the world) a - permission for everyone. Operators: + : add these permissions; - : take away these permissions; = : set EXACTLY these permissions, overriding whatever was there previously.

Computing II - Problem Session - 1. The permissions: r - Read; w - Write; x - Execute; Example: chmod og-rwx Simply means you won’t let the world do anything with your file or directory. You (the user) can still do anything you want. If you want to make a directory world accessible and readable but not changeable:

Computing II - Problem Session - 1. If you want to make a directory world accessible and readable but not changeable: chmod o=rx since you may want to descent into it. A file needs only chmod o=r since you won’t expect any operations on it other than Read. If it is an executable, you may want chmod o=rx Which will allow copying and executing.

Computing II - Problem Session - 1. If you don’t want others to change your stuff, make sure none of your files or directories have world write permission. Set group permissions the same as world, unless instructed otherwise.

Computing II - Problem Session - 1. To get the program files: Log in to your Unix account, create a directory and copy the files into it: > mkdir ps1 //create a directory for the files > cd ps1//make this the current working dir. > cp ~rdirkman/ps1/pointers/* ~/ps1/ > cp ~rdirkman/ps1/linklist/* ~/ps1/ > cp ~rdirkman/ps1/airports/* ~/ps1/ > cp ~rdirkman/ps1/josephus/* ~/ps1/

Computing II - Problem Session - 1. If you want to develop on your own PC - FTP from the Windows Desktop: assumes the files have been copied into your directory StartButton -> run -> open: ftp -> click on OK ftp> open cs... User: Password:... ftp> lcd a:\ Local directory now A:\ // so you copy INTO the floppy ftp> cd // if you need to change dir... // on cs ftp> ascii 200 Type set to A.

ftp> get pointers.c 200 Port command successful 150 Opening ASCII mode 226 Transfer complete Xxxx bytes received in xx seconds... // more file transfers via get ftp> get linklist.c... ftp> get airports.c... ftp> get selector.c... ftp> bye //ftp exits > exit //back to your Unix account Computing II - Problem Session - 1.

If you develop your programs on a PC, you must send the finished products to cs to test and for submission. Log in to your Unix account > mkdir ps1done //name as good as any > cd ps1done The go to Windows and start FTP ftp> open cs //login as before ftp> lcd a:\ ftp> pwd//see current working directory... ftp> cd ps1done//move to the correct directory ftp> send linklist.c //more sends - remaining finished files ftp> bye//terminate

Computing II - Problem Session - 1. Making sure that your programs run. > ls//have you got everything? Airports.c linklist.c selector.c > gcc linklist.c //or g++ linklist.c if you used C++ // this may indicate errors - if so, fix them // if successful you will have compiled and linked > a.out//will (try to) execute your program... > gcc airports.c//compile and link... > a.out//again, check > gcc selector.c//compile and link > a.out//again, check...//if it all works out, submit >submit giam ps1 readme linklist.c airports.c selector.c > exit

Computing II - Problem Session - 1. Developing programs under Unix requires that you learn to use some editor. CDE has a very simple editor and also access to emacs - which is, arguably, the most sophisticated customizable editor in existence. The learning curve is steep, but anyone who expects to make a living as a code jock (at least for a few years) should learn how to use it. For the programs: create a directory (>mkdir ps1 ) copy the program files into it edit each file as needed - emacs, vi, CDE,... compile the file with gcc (or g++) test by executing a.out submit all completed files

Computing II - Problem Session - 1. The process is identical to the one outlined for testing a program developed on a PC, except that all file editing and debugging will take place in some window under Unix, rather than off-line on the PC.