Diktat_ProgKecilBhsC

C body prototype type jam include jamh body prototype

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ca : %c \n", CC); retval = read (_handle, &CC, 1); } return 0; } /* fileint.c */ /* membuat dan membaca kembali file yang setiap rekamannya adalah integer */ #include <stdio.h> int main () {/* KAMUS */ int i; int rek; int retval; FILE *fileku; /* ALGORITMA */ /* Membuat */ fileku = fopen ("filein.dat", "w"); for (i = 1; i < 5; i++) { /* perhatikan format penulisan */ retval = fprintf (fileku, "%d ", i); } printf ("\nSelesai membuat ..."); fclose (fileku); /* Membaca kembali */ fileku = fopen ("filein.dat", "r"); retval = fscanf (fileku, "%d", &rek); /* harus sama dg ketika dibuat*/ printf ("%d ", rek); while (retval != EOF) { printf ("Yang dibaca : %d \n", rek); retval = fscanf (fileku, "%d ", &rek); } printf ("\nbye..."); fclose (fileku); return 0; } /* filerek.c */ /* membuat dan membaca kembali sebuah file yang rekamannya type terstruktur */ #include <stdio.h> int main () { typedef struct { int NIM; float Nilai; } TMhs; int i; TMhs Mhs; int retval; FILE *fileku; /* ALGORITMA */ fileku = fopen ("filerek.dat", "w"); for (i = 1; i < 5; i++) { Mhs.NIM = i; Mhs.Nilai = i * 0.8; retval = fprintf (fileku, "%d %f", Mhs.NIM, Mhs.Nilai); printf ("retval %d", retval); } printf ("\n selesai membuat..."); fclose (fileku); fileku = fopen ("filerek.dat", "r"); retval = fscanf (fileku, "%d %f", &Mhs.NIM, &Mhs.Nilai); printf ("retval %d \n", retval); while (retval != EOF) { printf ("Yang dibaca : %d %f \n", Mhs.NIM, Mhs.Nilai); retval = fscanf (fileku, "%d %f", &Mhs.NIM, &Mhs.Nilai); printf ("retval %d \n", retval); } printf ("\nbye..."); fclose (fileku); return 0; } /* filekoma.c */ /* membaca text file */ /* separator data adalah koma */ #include <stdio.h> int main () { /* kamus */ int x; char *cc[10]; int retval; /* program */ FILE *fileku; fileku = fopen ("koma.dat", "r"); retval = fsca...
View Full Document

This document was uploaded on 03/15/2014 for the course IF 2030 at Institut Teknologi Bandung.

Ask a homework question - tutors are online