• Stream definition :
A sequence of character. All
input and output data is a stream. C sees file as a stream.
• File Definition :
There are 2 types of File
• Text File
- Saved
in a text format or ASCII File
- Storage
size depends on its data: 10000 needs 5 byte
- Can
be open using standard text editor application
- Or
c:>TYPE file_name
• Binary File
storing
numerical data in affixed format in line with micro-processor format definition
(example: format sign-magnitude 2’s complement).
–File is a collection of record
–Record is a collection of field
–Field is a block of byte
–Byte is collection of bit
• How to open a File ?
Opening
a File using fopen():
FILE *fopen (const char *filename,
const char *mode );
fopen() defined
at <stdio.h>
fopen() return
a pointer to the start of a buffer area. Null will be returned if file unable
to open.
Types of mode you can use
Mode Description
“r” Opening a file to be read.
“w” Creating a file to be written.
“a” Opening a File for data append.
“r+” Opening a File for read/write.
“w+” Creating file for read/write.
“a+” Opening a File for read/append
“rb” Opening a File (binary) to be read.
“wb” Creating a file (binary) for write
operation.
Don't forget to close your opened file by using
int fclose
(FILE *stream);
No comments:
Post a Comment