Академический Документы
Профессиональный Документы
Культура Документы
Prepared by:
Johra Muhammad Moosa
Lecturer
Department of Computer Science & Engineering
Bangladesh University of Engineering & Technology
Stream
Abstraction between hardware and programmer
Actual device providing I/O is file
Stream is a logical interface to a file
When a C program started operating system opens three files and
associated streams
Standard input: stdin
Standard output: stdout
Standard error: stderr
Declared in stdio.h
Open a File
FILE *fopen (char *filename, char *mode);
Stdio.h
Filename
path
Mode
“r”, “w”, “a”, “rb”, “ab”, “r+”
Consequence of those modes
Returns a pointer to the opened file
If fails returns NULL
Mode
Read mode ("r")
if file is unavailable error
Write mode (“w")
if file is unavailable created
Append mode (“a")
if file is unavailable created
Close a File
int fclose (FILE *fp);
In order to improve efficiency most file system write data to disk
one sector at a time
fclose flushes the buffer
Read/Write a Character
int fgetc (FILE *fp);
fgetc(stdin) same as getchar()