1 / 10

FILE

FILE. Teks dan Biner. //program untuk menulis ke dalam file teks kemudian menampilkan isi file ke layar #include <stdio.h> #include <conio.h> #include <stdlib.h> Void main() { const int mak 80; file p; // deklarasi file. File Teks. // membuka file teks utk di isi

malory
Télécharger la présentation

FILE

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. FILE Teks dan Biner

  2. //program untuk menulis ke dalam file teks kemudian menampilkan isi file ke layar • #include <stdio.h> • #include <conio.h> • #include <stdlib.h> • Void main() { • const int mak 80; • file p; // deklarasi file File Teks

  3. // membuka file teks utk di isi • if( (p = fopen(“demo.txt” ,”w” ) ) == NULL) • { puts(“File tidak dapat di buka”); • exit(0); • } • // input dari keyboard dan di tulis ke file • char string[mak], jawab ; // deklarasi var

  4. do • { printf(“kalimat”); gets(string); • fprintf(p,”%s\n”,string); • printf(“lagi [ Y / T ]”); • scanf(“%c”,&jawab); • } while(toupper(jawab) ==‘Y’); • fclose(p); // tutup file jika sudah selesai

  5. //membaca file • if( (p = fopen(“demo.txt”,”r”) ) == NULL) • { puts(“File tidak dapat di buka”); • exit(1); • } • // tampilkan di monitor • while( (fscanf(p,”%s”,string)) != EOF) • printf(“%s\n”,string); • fclose(p); // tutup file • } // end program

  6. //program untuk menulis ke dalam file biner kemudian menampilkan isi file • #include <stdio.h> • #include <conio.h> • #include <stdlib.h> • Void main() • { • file p; // deklarasi file File Biner

  7. struct mhs • { char npm[8]; • int nilai; }; • mhs m; //deklarasi variabel • char jwb; //deklarasi variabel • // membuka file biner utk di isi • if( (p = fopen(“demo.dat” ,”wb” ) ) == NULL) • { puts(“File tidak dapat di buka”); • exit(0); • }

  8. // membaca dan simpan ke file biner • do • { • printf(“NPM “); gets(m.npm); • printf(“Nilai “); scanf(“%d”,&m.nilai); • fwrite(&m,sizeof(m),1,p); //save ke file • printf(“Lagi [Y/T]”);scanf(“%c”,&jwb); • } • while(toupper(jwb) ==‘Y’);

  9. // tampilkan ke layar • while( ( fread(&m,sizeof(m),1,p)) != NULL) • printf(“%s %d\n”,m.npm,m.nilai); • fclose(p); // tutup file • } // end program file biner

  10. Selesai

More Related