File AccessCS-2301, B-Term 20091 File Access CS-2301, System Programming for Non-Majors (Slides include materials from The C Programming Language, 2 nd.

Slides:



Advertisements
Similar presentations
I/O means Input and Output. One way: use standard input and standard output. To read in data, use scanf() (or a few other functions) To write out data,
Advertisements

UNIT 15 File Processing.
BITS Pilani, Pilani Campus TA C252 Computer Programming - II Vikas Singh File Handling.
File Management in C. A file is a collection of related data that a computers treats as a single unit. File is a collection of data stored permanently.
Homework #4CS-2301 B-term Homework #4 Strings, Arrays, and malloc() CS-2301, System Programming for Non-majors (Slides include materials from The.
Lecture 2 Introduction to C Programming
January 13, Csci 2111: Data and File Structures Week1, Lecture 2 Basic File Processing Operations.
Strings and Dynamic Memory Allocation CS-2301, B-Term Programming Assignment #6 Strings and Dynamic Memory Allocation CS-2301, System Programming.
 2007 Pearson Education, Inc. All rights reserved C File Processing.
CS1061 C Programming Lecture 17: Steams and Character I/O A. O’Riordan, 2004.
Chapter 11 C File Processing Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Discussion of Assignment #2 CS-2301, B-Term Discussion of Assignment #2 CS-2301, System Programming for Non-Majors (Slides include materials from.
Review of Exam #2CS-2301, B-Term Review of Exam #2 CS-2301, System Programming for Non-Majors (Slides include materials from The C Programming Language,
More on Numerical Computation CS-2301 B-term More on Numerical Computation CS-2301, System Programming for Non-majors (Slides include materials from.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.
More about Numerical Computation CS-2301, B-Term More about Numerical Computation CS-2301, System Programming for Non-Majors (Slides include materials.
Guide To UNIX Using Linux Third Edition
Binary TreesCS-2301, B-Term Programming Assignment #5 Binary Trees CS-2301, System Programming for Non-Majors (Slides include materials from The.
Assignment #2, 12- month Calendar CS-2301, B-Term Programming Assignment #2 12-Month Calendar CS-2301, System Programming for Non-Majors (Slides.
Console and File I/O - Basics Rudra Dutta CSC Spring 2007, Section 001.
C - Input & Output When we are saying Input that means to feed some data into program. This can be given in the form of file or from command line. C programming.
Binary Search Tree For a node: The left subtree contains nodes with keys less than the node's key. The right subtree contains nodes with keys greater than.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Guide To UNIX Using Linux Fourth Edition
A Guide to Unix Using Linux Fourth Edition
1 Homework Introduction to HW7 –Complexity similar to HW6 –Don’t wait until last minute to start on it File Access will be needed in HW8.
Standard Input and Output. Overview Data communication with a C program and the outside world is performed through files Files are a non-volatile way.
Lone Leth Thomsen Input / Output and Files. April 2006Basis-C-8/LL2 sprintf() and sscanf() The functions sprintf() and sscanf() are string versions of.
CP104 Introduction to Programming File I/O Lecture 33 __ 1 File Input/Output Text file and binary files File Input/output File input / output functions.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
Introduction to Programming Using C Files. 2 Contents Files Working with files Sequential files Records.
File IO and command line input CSE 2451 Rong Shi.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee C Language Part 4.
1 File Handling. 2 Storage seen so far All variables stored in memory Problem: the contents of memory are wiped out when the computer is powered off Example:
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
Basic I/O in C Computer Organization I 1 August 2009 © McQuain, Feng & Ribbens Stream Model of I/O header file: A stream provides a connection.
Input/output streams. Character Input / Output and Input Validation Input and output devices: keyboards, disk drives, mouse, monitors, printers, network.
CS113 Introduction to C Instructor: Ioannis A. Vetsikas Lecture 11 : September 18.
Files A collection of related data treated as a unit. Two types Text
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic properties and characteristics of external files ❏ To.
Advanced Programming in the UNIX Environment Hop Lee.
 2007 Pearson Education, Inc. All rights reserved C File Processing.
Silberschatz and Galvin  C Programming Language Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University College of Education.
Chapter 7 Text Input/Output Objectives
Chapter 7 Text Input/Output Objectives
Chapter 22 – part a Stream refer to any source of input or any destination for output. Many small programs, obtain all their input from one stream usually.
TMF1414 Introduction to Programming
Chapter 7 Text Input/Output Objectives
Revision Lecture
File I/O.
CS 261 – Recitation 7 Fall 2013 Oregon State University
CSC215 Lecture Input and Output.
Plan for the Day: I/O (beyond scanf and printf)
CS111 Computer Programming
CSE1320 Files in C Dr. Sajib Datta
File Input/Output.
CSE1320 Files in C Dr. Sajib Datta
Files I/O, Streams, I/O Redirection, Reading with fscanf
CSE1320 Files in C Dr. Sajib Datta
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
C Programming Lecture-15 File I/O
IO Overview CSCE 121 J. Michael Moore
Chapter Four UNIX File Processing.
Accessing Files in C Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition,
Fundamental of Programming (C)
Weeks 9-10 IO System Calls Standard IO (stdin, stdout) and Pipes
Module 12 Input and Output
CS1100 Computational Engineering
CSc 352 File I/O Saumya Debray Dept. of Computer Science
Presentation transcript:

File AccessCS-2301, B-Term File Access CS-2301, System Programming for Non-Majors (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie and from C: How to Program, 5 th and 6 th editions, by Deitel and Deitel)

File AccessCS-2301, B-Term Input and Output So far, all input and output has been to standard input and from standard output I.e., scanf() or getchar() printf() The computer terminal or other “official” media In most application and professional situations, you will need to read/write to files

File AccessCS-2301, B-Term File – Definition A persistent, named piece of data that is stored in the computer system for later use Can be very large (gigabytes) or small (0 bytes) Can live a very long time Typically used to remember stuff that outlives a particular running program Files serve all sorts of purposes Documents, databases, web pages, source code, object code, data from applications, …

File AccessCS-2301, B-Term Directory or Folder — Definition A special kind of file that is used to organize other files and directories Names of files and directories are defined in their containing directories (Usually) hierarchically organized /user/lauer/CodingExamples/craps.c S:\cs2301\public_html\b09\index.htm Name of file is last component of pathname Extension (e.g.,.txt,.c,.htm,.doc ) is by convention

File AccessCS-2301, B-Term Organization of Files Most files are organized as linear sequences of bytes Binary, text, international text In this course, we are most concerned with text files!

File AccessCS-2301, B-Term File I/O in C Before you can access a file you must open it! After you are done, you must close it! #include … FILE *fp; FILE *fopen(char *name, char *mode); int fclose(FILE *fp); A data type defined in

File AccessCS-2301, B-Term File I/O in C Before you can access a file you must open it! After you are done, you must close it! #include … FILE *fp; FILE *fopen(char *name, char *mode); int fclose(FILE *fp); The path name of the file. The “mode” of access.

File AccessCS-2301, B-Term FILE *fopen(char *name, char *mode) name may be Fully qualified:– e.g., C:\lauer\cs2301\lecture.ppt Relative to working directory:– lecture.ppt mode may be "r" – read only "w" – write only (create or discard previous contents) "a" – append only (write at end; create if necessary) "r+" – read and update (i.e., read-write) "w+" – read-write (create or discard previous contents) "a+" – read-append (write at end; create if necessary) Add "b" to mode string for binary files

File AccessCS-2301, B-Term File Input int fscanf(FILE *fp, char *format, …) Same as scanf, but from an open file int getc(FILE *fp) Gets one character from FILE *fp Same as getchar() but from the file In fact, see p. 161! #define getchar() getc(stdin) FILE *stdin; /* declared in */

File AccessCS-2301, B-Term File Output int fprintf(FILE *fp, char *format, …) Same as printf, but to an open file int putc(FILE *fp) Puts one character to FILE *fp Same as getchar() but to the file In fact, see p. 161! #define putchar() putc((c), stdout) FILE *stdout; /* declared in */

File AccessCS-2301, B-Term Standard input and output stdin – the “standard” source of input Terminal keyboard Read-only Piped from a file using "<" or "|" stdout – the “standard” output destination Terminal window Append only Piped to a file using ">" or "|" stderr – another “standard” output destination Terminal window Append only Normally used for error messages

File AccessCS-2301, B-Term Using File I/O Lab 5, part 2 Complete on your own time Programming Assignment #5 Programming Assignment #6 More or less anything you do in WPI or professional applications

File AccessCS-2301, B-Term Questions?