CHAPTER 3 INPUT/OUTPUT List-directed (free formatted) input/output As in section 2.6 Formatted input/output General Form: Read format-specifier, input-list.

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

Single Variable and a Lot of Variables The declaration int k; float f; reserve one single integer variable called k and one single floating point variable.
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 *
Chapter 3. Expressions and Interactivity CSC125 Introduction to C++
Chapter 5 Basic I/O Concepts Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul - Turkey Tel:
1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
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.
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.
Lecture 5 Input and Output inputfprintf © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Formatted Output What we know: write(*,*) x print *, x General Form: write (unit, format, options) list unit = * : write to the monitor format = *: no.
2.4 The Assignment Statement Values are assigned to variables using the assignment statement : variable = expression Examples: Ex.1: REAL :: XCoordinate,
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
Chapter 5 Input / Output. 2 Control over input & output  The input and output are basically facilitates a communication between the user and the program.
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.
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
C Formatted Input/Output /* Using Integer Conversion Specifiers */ #include int main ( ) { printf( "%d\n", 455 ); printf( "%i\n", 455 ); printf( "%d\n",
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(,,,..., );
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)
Generalized I/O. Mystery of stars I/O statements took the form read *, x, y,z print *, a,b,c Such I/O is said to be List-directed or in free format user.
Expressions and Interactivity Chapter 3. 2 The cin Object Standard input object Like cout, requires iostream file Used to read input from keyboard Often.
© 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.
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.
Fortran 1- Basics Chapters 1-2 in your Fortran book.
Chapter 9 Formatted Input/Output Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
1 The CONST definition CONST Pi = , City = ‘New York’; Constant identifiers are used when you do not want the value of an identifier to change why.
Chapter 8: Collections: Arrays. 2 Objectives One-Dimensional Arrays Array Initialization The Arrays Class: Searching and Sorting Arrays as Arguments The.
1 Week 2 n Organizational matters n Fortran 90 (subset F): Basics n Example programs in detail.
Why Files? ♦ the amount of data read and / or produced is huge ♦ repetitive data is needed for more than one program ♦ data may be entered by other people.
Chapter 7 Formatted input and output. 7.1 introduction Tax: This result is correct; but it would be better Maybe as $13, Make formatting.
Chapter 3: Formatted Input/Output Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
INPUT / OUTPUT STATEMENTS
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.
Chapter-4 Managing input and Output operation.  Reading, processing and writing of data are three essential functions of a computer program.  Most programs.
Sections 5.1 – 5.4 © Copyright by Pearson Education, Inc. All Rights Reserved.
1 STRINGS String data type Basic operations on strings String functions String procedures.
21 April, 2000 CS1001 Lecture 22 Formatted Input and Output.
Introduction to Computer Organization & Systems Topics: Types in C: floating point COMP C Part III.
Operating System Discussion Section. The Basics of C Reference: Lecture note 2 and 3 notes.html.
19 - 2/25/2000AME 150L1 Solving Systems of Linear Equations.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 2 (Tuesday)
Utility1 UTILITY PACKAGE One-dimensional real arrays and two dimensional integer and real arrays are read by utility packages. There is no utility package.
1 ENERGY 211 / CME 211 Lecture 7 October 6, 2008.
Input and Output Output Prompt: –A message displayed to the user indicating what they are to enter. Should be clear and exact on what you want. write:
CCSA 221 Programming in C INPUT AND OUTPUT OPERATIONS IN C – PART 1 1.
Chapter 3: Formatted Input/Output 1 Chapter 3 Formatted Input/Output.
CSCE Do Loops Simplest form DO j = 1,100 PRINT *,j END DO Variable j runs from 1 to 100 counting by ones.
Week 9 Controling I/O. Today’s program Review of the last quiz Q&A about last weeks topics New topic: I/O formatting.
Chapter 9 - Formatted Input/Output
Formatted Input/Output
CPS120: Introduction to Computer Science
Formatted Input/Output
OUTPUT STATEMENTS GC 201.
CSI 121 Structured Programming Language Lecture 7: Input/Output
Lecture 13 Input/Output Files.
The University of Texas – Pan American
Chapter 9 - Formatted Input/Output
Chapter 3: Input/Output
Chapter 3: Expressions and Interactivity
CS150 Introduction to Computer Science 1
FILE PROCESSING Opening Files Why Files?
Repetition Structures
Week 10 FILE PROCESSING.
OUTPUT DESIGN PRINT K, expression list K FORMAT (specification list)
Presentation transcript:

CHAPTER 3 INPUT/OUTPUT List-directed (free formatted) input/output As in section 2.6 Formatted input/output General Form: Read format-specifier, input-list

1.* (an asterisk) It indicates list-directed input (free format). Example: read *,a,j 2.A character constant or a character variable (or expression or array) whose value specifies the format for the input. Example: read ‘(I3,I4,I7)’,j,k,l 3.The label of a FORMAT statement label FORMAT (list of format descriptors)

Descriptors Example: Read 10, I, r, t 10 format (2x, i5, f7.3, f6.2)

X- Descriptor It skips positions on the data line General Form: nX I- Descriptor It is used when reading a value into an integer variable. General Form: nIw w : width of the field and n is the repetition indicator. Example: read 10,m,n 10 format(5x,i5,i7)

F- Descriptor It is used when reading a value into a real variable. General Form: Fw.d w: total number of positions to use from the data line and d: number of decimal positions. REMARKS: If there is a decimal point included in the w positions, the value will be stored as it was entered, regardless of what value has been given to d. If there is no decimal point within the specified positions, the value of d is used to position a decimal place before storing the value. If the characters 1246 are read using F4.1, the value stored is

Example: Read 10, I, r, t 10 format (2x, i5, f7.3, f6.2) Example: read 50,a,c,k 50 format(2x,2f5.1,2x,i4) For: a=80.1, c=36.5 and k = 40, the input line should be as: x2f5.12xI4

E- Descriptor used to read a variable entered in an exponential form. General Form: Ew.d W: total number of positions to use from the data line and d: the number of decimal positions. Example: read 30,Iter,error 30 format(2x,i5,2x,e7.2) Data line, Iter=12 and error=0.25e-09: 12.25E-09 2xI52xE7.2

A-Descriptor used to read character variable. General Form: Aw Where w represents the number of positions to be read.

Output Formatting Similar to input formatting Only one difference  Carriage Character Control  Single space used to control output Carriage Character Control characters to be printed

Example: Print 4 4 Format(‘Fortran course') The buffer output line: And the output is: Fortrancourse ortrancourse Example: Print 4 4 Format(1x‘Fortran course') The buffer output line: And the output is: FortranCourse Fortrancourse

More Examples Example 1: Given: K=20, L=-30, M=-450 Print 4, K,L,M 4 Format(1X,I3,2X,I2,3X,I4) Example 2: Given: T= , R= Print 4, T,R 4 Format(1X,E10.2,3X,F7.3)