Algoritma dan Pemograman Review (Session 8)

File Processing:

–Files and Streams

–File Definition

–Open File

–Close File

–Input File

–Output File

Definisi File, record dan penyusunnya :

File is a collection of record
Record is a collection of field
Field is a block of byte
Byte is collection of bit

Definisi Streams 

  • To keep key in data from keyboard need to be saved at secondary storage device as a data file.
  • Stream is a sequence of character. All input and output data is a stream. C sees file as a stream.

ketika kita menjalankan Program yang dibuat dengan bahasa C dan turunnanya maka program itu menjalankan 3 jenis stream:

  1. Standard Input Stream

Controlling input stream from keyboard

  1. Standard Output Stream

Controlling output stream to the monitor

  1. Standard Error Stream

Controlling the error messaging

yang masing masing tersingkronisasi dengan File yang diakses

 

ada beberapa jenis 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).

dalam mengakses file kita akan membuka dan menutup file

yang perintanya ada di header <stdio.h>

Opening a File using fopen():

dengan menuliskan :  FILE *fopen (const char *filename, const char *mode );

  •   “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.

setlah membuka file maka filenya harus di tutup dengan :

fungsi fclose() yang sudah ada di <stdio.h>

  • fclose() will return 0 if successful, and EOF if error
  • EOF (End Of File) equals to -1
  • fclose() will release the buffer area and immediately send the remaining data to file.

Leave a Reply

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