lecture17-mar1 - Announcements - Lecture 17 Assignment 4...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Announcements - Lecture 17 • Assignment 4 – out today – Q&A – Lines of code counter – Designs due in recitation Friday • IPO, functional block diagram, algorithm (high level) • Topics for today – start File IO (rest of Chapter 22, minus 22.3) • Files and streams • Text IO operations • Formatted file IO operations Files A file is — 1. A named collection of related data stored on a secondary storage device , such as disk, diskette, flash stick, CD, etc. • Permanent — data survives indefinitely. 2. Most OS’s support two different types of files: text and binary Text files are stored as a sequence of lines; with end of line markers Binary files are not Files on here: e.g. •tfgrading.c •assn2data.txt •myresume.doc •mypgm.exe Hard Disk Drive Basic Operations on Files • Open – in a specific mode • Read – usually sequentially • Write – usually sequentially • Close file1 EOF Disk Name Access mode Size Current location ptr File descriptor FILE *fp; text files and binary files are stored differently The data is converted to/from stream format when transferred (e.g. buffered) Streams A stream is an abstraction of the continuous one-way flow of data between a program and an external device (e.g., keyboard or screen) or files on a secondary storage device (e.g. disk). A stream is categorized into one of two types: binary (byte) stream or character (text) stream . They transfer one data element at a time (a byte or character) in sequential order. Binary streams contain non printable bit patterns. Program In memory Output Stream File on disk Input Stream File Pointers and Streams Declarations of functions that perform file I/O appear in <stdio.h>. Each function requires a file pointer as a parameter. A file pointer is a pointer to a FILE description structure, it is declared as: FILE *fp; /* fp holds a pointer to a file descriptor */ A program may declare as many file pointers as needed A file pointer represents a stream, which may be a file or—in general—any source of input or output. Three streams are standard: stdin Standard input (keyboard) stdout Standard output (screen) stderr Standard error (different window on the screen) These streams need not be explicitly opened/closed by you Standard input and output can be redirected in both UNIX and Windows from the command line: prog <data.txt >result.txt
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Opening and Closing Files Files can be opened by calling the fopen()
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/15/2010 for the course EE 16005 taught by Professor Krasner during the Spring '10 term at University of Texas at Austin.

Page1 / 3

lecture17-mar1 - Announcements - Lecture 17 Assignment 4...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online