Input/Output and the Operating Systems - PowerPoint PPT Presentation

About This Presentation
Title:

Input/Output and the Operating Systems

Description:

fopen() and fclose() A file should be opened before being used. why? After used, it is better to be closed. to flush the buffer (fflush) BTW, what is a file? – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 16
Provided by: skk49
Learn more at: http://csl.skku.edu
Category:

less

Transcript and Presenter's Notes

Title: Input/Output and the Operating Systems


1
Input/Output and theOperating Systems
2
Review
  • union
  • sizeof( ) function
  • bit fields

3
I/O Functions
  • Formatted I/O
  • printf( ) and scanf( )
  • fprintf( ) and fscanf( )
  • sprintf( ) and sscanf( )

4
  • FILE structure is defined in stdio.h
  • you dont want to know details now
  • Three standard file pointers defined in stdio.h
  • stdin
  • stdout
  • stderr

5
I/O Functions
6
(No Transcript)
7
(No Transcript)
8
fopen() and fclose()
  • A file should be opened before being used
  • why?
  • After used, it is better to be closed
  • to flush the buffer (fflush)
  • BTW, what is a file?
  • a sequence of bytes(characters)
  • these bytes can be accesses sequentially/randomly

9
Standard Files
  • The system opens the three standard files
  • stdin, stdout, stderr
  • printf/scanf functions work with stdout/stdin
  • screen/keyboard in most cases

10
fopen()
FILE fopen(const char filename, const char
mode)
  • performs housekeeping to use a file
  • access right
  • availability
  • data structures for a file
  • successful call returns a file pointer
  • unsuccessful call returns NULL

11
  • mode is either r or w or a
  • for w or a, a new file is created if it
    doesnt exist
  • r for open a text file for read/write
  • rb to read a binary file
  • fseek()
  • initially, fp points the beginning of the file
  • the fp points the next byte to be accesses
  • fseek() sets the value of fp

12
tmpfile( ) creates a temporary file that will be
deleted when it is closed or when the program
exits
13
(No Transcript)
14
Executing Commands
int system(const chat s)
  • system(date) / date is a command /
  • legal set of commands differ system to system

15
Timing
  • there is a very accurate clock inside a computer
  • lttime.hgt file defines clock_t and time_t
  • clock_t clock(void)
  • the time used by this program
  • time_t time(time_t p)
  • seconds elapsed since 1/1/1970
Write a Comment
User Comments (0)
About PowerShow.com