“The fastest I/O is no I/O.” Nils-Peter Nelson, Bell Labs

Slides:



Advertisements
Similar presentations
Character Arrays (Single-Dimensional Arrays) A char data type is needed to hold a single character. To store a string we have to use a single-dimensional.
Advertisements

Chapter 3. Expressions and Interactivity CSC125 Introduction to C++
Dale Roberts Basic I/O – printf() CSCI 230 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Department of.
1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
Announcements Quiz 1 Next Week. int : Integer Range of Typically -32,768 to 32,767 (machine and compiler dependent) float : Real Number (i.e., integer.
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
1 CSE1301 Computer Programming: Lecture 9 Input/Output.
CS 161 Introduction to Programming and Problem Solving Chapter 13 Console IO Herbert G. Mayer, PSU Status 9/8/2014 Initial content copied verbatim from.
The printf Method The printf method is another way to format output. It is based on the printf function of the C language. System.out.printf(,,,..., );
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
C Programming Lecture 3. The Three Stages of Compiling a Program b The preprocessor is invoked The source code is modified b The compiler itself is invoked.
Chapter 5: Data Input and Output Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
Chapter 9 Formatted Input/Output Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
 Pearson Education, Inc. All rights reserved Formatted Output.
EPSII 59:006 Spring Introduction In this lecture  Formatted Input/Output scanf and printf  Streams (input and output) gets, puts, getchar, putchar.
 2005 Pearson Education, Inc. All rights reserved Formatted Output.
C-Language Keywords(C99)
Constants in C A Presentation On Department of Computer & Information Technology, M.S.P.V.L. Polytechnic College, Pavoorchatram.
Characters The data type char represents a single character in Java. –Character values are written as a symbol: ‘a’, ‘)’, ‘%’, ‘A’, etc. –A char value.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
Syntax and Semantics, and the Program Development Process ROBERT REAVES.
3. FORMATTED INPUT/OUTPUT. The printf Function The first argument in a call of printf is a string, which may contain both ordinary characters and conversion.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI C-Style Strings Strings and String Functions Dale Roberts, Lecturer.
Ajmer Singh PGT(IP) Programming Fundamentals. Ajmer Singh PGT(IP) Java Character Set Character set is a set of valid characters that a language can recognize.
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!)
By Mr. Muhammad Pervez Akhtar
PRACTICAL COMMON LISP Peter Seibel 1.
C is a high level language (HLL)
Input Streams “A program designed for inputs from people is usually stressed beyond the breaking point by computer-generated inputs.” Dennis Ritchie, Bell.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
Formatted I/O ä ä Standard Output ä ä printf() family of functions ä ä Standard Input ä ä scanf() family of functions.
28 Formatted Output.
C Formatted Input/Output
C++ First Steps.
Programming what is C++
NUMBER SYSTEMS.
Chapter-01 A Sample C++ Program.
Chapter 2: Introduction to C++
ECE Application Programming
Wel come.
TMF1414 Introduction to Programming
Introduction to C CSE 2031 Fall /3/ :33 AM.
Getting Started with C.
Formatted I/O The read and print statements are very limited
CSI 121 Structured Programming Language Lecture 7: Input/Output
Programming in Perl Introduction
Lecture 13 Input/Output Files.
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
C++ fundamentals Lecture 1, Chapter 2 – pp /22/2018 Y K Choi.
Introduction to C++ Programming
An overview of Java, Data types and variables
Introduction to Primitive Data types
Homework Applied for cs240? (If not, keep at it!) 8/10 Done with HW1?
C Programming Getting started Variables Basic C operators Conditionals
EECE.2160 ECE Application Programming
Introduction to C EECS May 2019.
EECE.2160 ECE Application Programming
Introduction to C CSE 2031 Fall /15/2019 8:26 AM.
Introduction to Primitive Data types
EECE.2160 ECE Application Programming
Presentation transcript:

“The fastest I/O is no I/O.” Nils-Peter Nelson, Bell Labs Output Streams “The fastest I/O is no I/O.” Nils-Peter Nelson, Bell Labs

Streams All input and output is accomplished via streams A stream is a something from which data can be read and to which data can be written You’ve likely worked with streams before in other programming languages

Standard Streams There are several streams built in, including: *standard-input* *standard-output* *error-output* *terminal-io* *query-io* *debug-io*

(not (equal #\B #\b)) → T Characters Strings are made up of characters Examples: #\A, #\t, #\Newline Self-quoting: #\A → #\A Every character has an associated integer, usually its ASCII number Case sensitive: (not (equal #\B #\b)) → T

Codes and Chars There are many built-in functions for working with characters char-code returns the number associated with a character code-char returns the character associated with a number char<, char<=, char=, char>=, char> and char/=

Predicates for Characters characterp alpha-char-p digit-char-p alphanumericp upper-case-p lower-case-p both-case-p graphic-char-p standard-char-p

Writing to Streams Plethora of possibilities >(print "Lisp rocks my socks off!" *standard-output*) "Lisp rocks my socks off!" >(write-char #\S *standard-output*) S #\S >(write-string "Hello" *standard-output*) Hello "Hello“ In the above examples, *standard-output* is actually optional because it is the default output stream: >(print "Lisp rocks my socks off!")

Writing From a Progn Block >(progn (print "Hi") (write-string "class")) "Hi" class "class" (terpri) "Hi" class terpri is a carriage return

More Writing Functions prin1 – like print, but no newlines or spaces between calls princ – like prin1, but no double quotes around output strings pprint – like print, but doesn’t return the string printed (also makes output “pretty”) fresh-line – goes to beginning of next line, unless you’re already at the beginning (terpri always goes to next line)

(format destination template S-expr*) Most general and powerful output function (format destination template S-expr*) destination can be a stream, t or nil If t, result is printed to currently selected output device Returns NIL, unless destination is nil, in which case the string produced is returned and no stream is written to

Format (2) Format has a complex set of directives that are close to a programming language in terms of expressive power Format directives are indicated with a ~ Can indicate spacing information and printing specifications Somewhat similar to printf in C

Basic Format Directives Two primary directives: ~S and ~A Not case sensitive ~S prints in a format that LISP can read ~A simply prints “nice” output These will often look the same, but not always

Format Examples >(format t "This is a test") This is a test NIL >(format t "This is a ~A" "test") >(format t "This is a ~S" "test") This is a "test" >(format t "This is an ~S" 'example) This is an EXAMPLE

Other Useful Directives ~~ - prints a ~ ~& - like fresh-line ~% - like terpri ~D - decimal number ~B - binary number ~O - octal number ~X - hexadecimal number ~F - fixed-format floating point number ~E - exponential floating point number ~G - general floating point number ~$ - money format, meaning fixed floating point with two decimals