Formatted Output What we know: write(*,*) x print *, x General Form: write (unit, format, options) list unit = * : write to the monitor format = *: no.

Slides:



Advertisements
Similar presentations
Input and Output READ WRITE OPEN. FORMAT statement Format statements allow you to control how data are read or written. Some simple examples: Int=2; real=
Advertisements

CHAPTER 5 INPUT/OUT FORMAT. Introduction READ (*,*) x WRITE (*,*) x This is free format: the first * is for I/O device number (* = input is keyboard *
BITS Pilani, Pilani Campus TA C252 Computer Programming - II Vikas Singh File Handling.
Chapter 3. Expressions and Interactivity CSC125 Introduction to C++
Fortran 4- Reading and Writing from Data Files Chapter 4 of your Fortran book.
11/06/20151 FORTRAN 77 Programming. Lecture 5 : January 2001 Dr. Andrew Paul Myers.
MORE ON… MAKING YOUR OUTPUT LOOK NICE! MET 50. Pretty output Recall the more sophisticated PRINT statement: PRINT nn, GRAV nn FORMAT (stuff) We use the.
The scanf Function The scanf function reads input from the standard input device into one or more variables Example: scanf(“%lf”, &miles); Reads a real.
Input and output. Input streams n there are two ways of handling I/o n list-directed –done using default settings –PRINT*, num –READ*, num n formatted.
Lecture 5 Input and Output inputfprintf © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
1 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
Revision – A simple program How to start a program? How to end a program? How to declare variables? What are the mathematical operators? How to start a.
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
1 CSE1301 Computer Programming: Lecture 9 Input/Output.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.
Guide To UNIX Using Linux Third Edition
CHAPTER 6 FILE PROCESSING. 2 Introduction  The most convenient way to process involving large data sets is to store them into a file for later processing.
Basic Input/Output and Variables Ethan Cerami New York
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(,,,..., );
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
Example in Final Fall 2006 PROGRAM EXAM IMPLICIT NONE INTEGER :: A=3, B=8 REAL :: CALC B = CALC(A, B) A = CALC(A, B) WRITE(*,*) A, B END PROGRAM EXAM a)
Introduction to C++ - How C++ Evolved Most popular languages currently: COBOL, Fortran, C, C++, Java (script) C was developed in 1970s at AT&T (Richie)
 Pearson Education, Inc. All rights reserved Formatted Output.
 2005 Pearson Education, Inc. All rights reserved Formatted Output.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
Copyright 1999 by Larry Fuhrer. Pascal Programming Getting Started...
1 Input / Output Input – reads/gets data for the program Output – the product, after processing Both can be: interactive I/O (while program is running)
Input/Output Sujana Jyothi C++ Workshop Day 2. C++ I/O Basics 2 I/O - Input/Output is one of the first aspects of programming that needs to be mastered:
1 Simple Input/Output  C++ offers the iostream library, which defines a system of character-oriented Input/Output (I/O) using object oriented programming.
Chapter 3 Input and Output
Data,information Data and Information 4 Data –Raw, unorganised facts –Ideas or concepts 4 Information –When data is manipulated into a meaningful form.
21 April, 2000 CS1001 Lecture 22 Formatted Input and Output.
Scientific Notation Ms. A. Trevino. Scientific Notation The form that you usually write numbers in is standard notation. A number is in scientific notations.
Chapter -7 Basic function of Input/output system basics and file processing Stream classes : I/O Streams. A stream is a source or destination for collection.
E-1 University of Washington Computer Programming I Lecture 5: Input and Output (I/O) © 2000 UW CSE.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Input and Output.
Chapter 3: Input/Output. Objectives In this chapter, you will: – Learn what a stream is and examine input and output streams – Explore how to read data.
Department of Electronic & Electrical Engineering IO reading and writing variables scanf printf format strings "%d %c %f"
Integers/Characters Input/Output Integers and Characters Input/Output System Calls. syscall Trap Handler Services for Integers and Characters Read Integer,
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic properties and characteristics of external files ❏ To.
Lecture 20: C File Processing. Why Using Files? Storage of data in variables and arrays is temporary Data lost when a program terminates. Files are used.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
BIL 104E Introduction to Scientific and Engineering Computing Lecture 2.
Formatted I/O ä ä Standard Output ä ä printf() family of functions ä ä Standard Input ä ä scanf() family of functions.
Awk 2 – more awk. AWK INVOCATION AND OPERATION the "-F" option allows changing Awk's "field separator" character. Awk regards each line of input data.
Chapter 4 Strings and Screen I/O. Objectives Define strings and literals. Explain classes and objects. Use the string class to store strings. Perform.
Chapter 3 Using Variables, Constants, Formatting Mrs. UlshaferSept
28 Formatted Output.
SCIENTIFIC NOTATION LESSON 19.
Introduction to programming in java
Chapter 7 Text Input/Output Objectives
Chapter 7 Text Input/Output Objectives
Integers/Characters Input/Output
Chapter 7 Text Input/Output Objectives
TMF1414 Introduction to Programming
Input and Output Statements
Chapter 2 part #3 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.
CSI 121 Structured Programming Language Lecture 7: Input/Output
Programming in Perl Introduction
Lecture 13 Input/Output Files.
IO Overview CSCE 121 J. Michael Moore
Class Examples.
Scientific Notation.
Fundamentals of Python: First Programs
The keyboard is the standard input device.
Chapter 2 part #3 C++ Input / Output
The monitor shows information.
IO Overview CSCE 121 Strongly influenced by slides created by Bjarne Stroustrup and Jennifer Welch.
Presentation transcript:

Formatted Output What we know: write(*,*) x print *, x General Form: write (unit, format, options) list unit = * : write to the monitor format = *: no specified format or free format or print format, list Formatted output: WRITE ( *, 150 ) X 150FORMAT ( 1X, F5.2 ) WRITE ( *, '( 1X, F5.2 )' ) X □□ 1.00 □□□□□□

Letter Code for Formatting a: character data I: integer data (I8: 8 spaces) F: real data in decimal notation (F12.4 : total number of spaces is 12, 4 digits after the decimal point) E: real data in scientific notation (E12.4) x: space ( 5x: 5 empty spaces) WRITE ( *, 150 ) X 150FORMAT ( 1X, F5.2 ) WRITE ( *, 100 ) 55, 55.0, FORMAT ( 1X, 'I, F and E format: ', I3, 1X, F5.2, 1X, E10.2 ) This outputs (to the screen) the line #I, F and E format: #55#55.00###0.55E+02 Note: # indicates an empty space, which is not in a text string.

Formatted Output-examples 1) WRITE ( *, 100 ) 55, 55.0, FORMAT ( 1X, 'I, F and E format: ', I3, 1X, F5.2, 1X, E8.2 ) 2) WRITE ( *, 100 ) 'I, F and E format: ', 55, 55.0, FORMAT ( 1X, A, I3, 1X, F5.2, 1X, E8.2 ) 3) I = 55 F = 55.0 E = 55.0 WRITE ( *, 100 ) 'I, F and E format: ', I, F, E 100 FORMAT ( 1X, A, I3, 1X, F5.2, 1X, E8.2 ) Are the outputs same? Yes.

Formatted Input What we know: read(*,*) a, b, c read *, a, b, c General Form: read (unit, format, options) variable_list unit = *: read from keyboard format = *: no specified format or free format or read format, variable_list Formatted input: READ ( *, 100 ) a, b, c 100FORMAT ( 3F10.2 ) Which are the correct inputs from keyboard? ,2,3 1.0, 2.0, , 2,00, , 2.000, 3.000

Disk I/O General form: OPEN ( [UNIT=] unit, FILE = file_name [, specifiers]) READ ( unit, format [, options] ) variable_list WRITE ( unit, format [, options] ) list CLOSE ( [UNIT=] unit [, STATUS = status]) [ ]: optional Example: PROGRAM NEWDATAFILE OPEN (UNIT=14,FILE=’fred.DAT’, STATUS=’NEW’) ! open fred.DAT and link it to unit=14 WRITE (*,*) ‘ TYPE IN A LIST OF REAL NUMBERS,ENDING WITH A LETTER’ 100 READ (*,1000,ERR=101)X! input from keyboard WRITE (*,1000) X! output to monitor screen WRITE (14,1000) X! output to fred.DAT GOTO CLOSE(14)! close fred.DAT 1000 FORMAT (F12.3) END

Disk I/O How to read data from fred.DAT? N=0 OPEN (UNIT=14,FILE=’fred.DAT’, STATUS=’OLD’) 100 READ(14, 1000, ERR=101) X! trapping input errors N = N + 1 GOTO CLOSE(14)