Algo part sekian

January 21st, 2016

FILE *pointer untuk memberi address dimana file akan disimpan dalam memory.

cara membuka file : pointer = fopen(“nama_data.txt” ,” mode”);
cara menutup file : fclose(pointer);

Mode-mode yang ada;
“r” membuka file untuk dibaca.
“w” membuat file untuk ditulis.
“A” membuka file untuk data append.
“r+” membuka file untuk membaca / menulis.
“w+” membuat file untuk membaca / menulis.
“a+” membuka file untuk membaca / tambahkan
“rb” membuka File (binary) untuk dibaca.
“wb” membuat file (binary) untuk menulis.

Mengenai EOF:
– fclose () akan memberikan return value 0 jika berhasil, dan EOF jika error
– EOF (End Of File) sama dengan -1 (EOF itu dibuat otomatis)
– fclose () akan masuk ke buffer area dulu dan segera mengirimkan data yang tersisa untuk file.
– !feof(file) -> membaca sampai akhir file
– boleh juga pake !=EOF

hal-hal penting ketika berurusan dengan string.
atoi : mengubah  ascii to int
itoa : mengubah int to ascii
strcat : menggabung string
fflush : menghapus hapus buffer
strcmp : membandingkan 2 string (0 jika benar)
strcmpi : strcmp yang tidak membedakan huruf besar dan kecil

Algo part 6

January 7th, 2016

FILE

syntax: FILE *filepointer;
filepointer = fopen(“*filename*”,”*mode*”);
fclose(filepointer);

mode:

r    : Open text file for reading. The stream is positioned at the beginning of the file.
r+  : Open for reading and writing. The stream is positioned at the beginning of the file.
w   : Truncate file to zero length or create text file for writing. The steam is positioned at the beginning of the file.
w+ : Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file.
a    : Open for writing. The file is created if it does not exist. The stream is positioned at the end of the file. Subsequent writes to the file will always end up at the then current end of file, irrespective of any intervening fseek(3) or similar.
a+  : Open for reading and writing. The file is created if it does not exist. The stream is positioned at the end of the file. Subse- quent writes to the file will always end up at the then current end of file, irrespective of any intervening fseek(3) or similar.