File Processing

File Processing

File Definition

File is a collection of record (Kumpulan baris)

Record is a collection of field

Field is a block of byte

Byte is collection of bit

Byte terdiri dari 8 bit

3 macam stream:

-) Standard input stream (stdin) : Controlling input stream from keyboard

-) Standard ouput stream (stdout) : Controlling output stream to the monitor

-) Standard error stream (stderr) : Controlling the error messaging

Text file saved in a text format or ASCII

Storage size data: 10.000 needs 5 byte

Orc:> TYPE = file name

Binary File

hanya bisa dibuka data sendiri

Buffer Area

Syntax:

FILE*FP;

Open File

Opening a File using fopen():

FILE *fopen (const char *filename, const char *mode );

fopen() defined at <stdio.h>

“r” (opening a file to be read)

“w” (creating file to be written)

“a” (opening a file for data append)

“r” (opening a file for read or 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)

 

Close File

Closing a file using fclose( ):

Int fclose (File*stream) :

f close. ( ) definied at <stdio.h> (menutup file)

 

f close (m ) will return o if succesful and EOF if error

EOF (End Of File) equals to -1

f close ( ) will release the buffer area and send the remaining data file

Closing a File using fcloseall():

int fcloseall (void);

Close all active stream except: stdin, stdout, stdprn, stderr, and stdaux.

Will return the number of stream closed if successful, and return EOF instead.

Header file <stdio.h>

 

input and ouput file

f gets (Input)

f puts(Output)

f scanf (Input)

f printf (output)

f write

f read

feof

  • Example using fwrite():

fwrite( &mhs, sizeof( mhs ), 1, fp );

  • &mhs = data origin location
  • sizeof(mhs) = return the size of mhs
  • 1 => one time write sizeof(mhs)
  • fp = file pointer

 

Leave a Reply

Your email address will not be published. Required fields are marked *