{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This preview shows pages 1–2. 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
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern