A file is often used to store data for a program - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

A file is often used to store data for a program

Description:

Hemingway, Ernest. Joyce, James. Yolen, Jane. DiCamillo, Kate. Coville, Bruce. text file ... A file stream is a one-way transmission path used to connect a data ... – PowerPoint PPT presentation

Number of Views:51
Avg rating:3.0/5.0
Slides: 9
Provided by: ETS38
Category:
Tags: and | data | ernest | file | hemingway | john | kate | program | store | used

less

Transcript and Presenter's Notes

Title: A file is often used to store data for a program


1
Files (i)
  • A file is often used to store data for a program

2
Files (ii)
  • A file has an external name and is managed by the
    operating system

3
File Streams (i)
  • A file stream is a one-way transmission path used
    to connect a data file to a C program
  • An input file stream receives or reads data from
    a file into a C program
  • An output file stream sends or writes data to a
    file from a C program

4
File Streams (ii)
  • A distinct file stream object must be created for
    each file a C program uses

names.txt
include ltfstreamgt
C PROGRAM
grades.txt
ifstream
ofstream
ifstream
courses.csv
5
File Stream Functions (i)
  • Begin by opening a file for reading or writing
  • Use the open() function

6
File Stream Functions (ii)
  • Functions to use in if stmts and while loops

7
File Stream Functions (iii)
  • When youre done, be sure to close each file
  • Use the close() function

8
In-Class Exercises
  • Write a program to read in letters.txt
  • Store each letter as an element in an array
  • Ask the user to type in a number 1-26 and output
  • The 23rd letter of the alphabet is W
  • The 7th letter of the alphabet is G
  • Write a program to read in numbers.txt
  • Store each number as an element in an array
  • Calculate the average, minimum, and maximum
Write a Comment
User Comments (0)
About PowerShow.com