Search

Tuesday, November 29, 2011

Structured Programming Example Using fseek

/ * -------------------------------------------- * / / * File program: BACAACAK.C * / / * To view the contents of a file at random * / / * -------------------------------------------- * / # Include "stdio.h" # Include "conio.h"
  
main () {
 
struct
 
{
  
char title [26];
  
char author [20];
  
int number;
 
Books} / * variable of type integer books * /
 
FILE * pf; / * clever file * /
 
char back;
 
int nmr_record, hasil_baca;
 
ofset_byte long int;
  
 
clrscr ();
  
 
/ * Open file contains data yan book * /
 
if ((pf = fopen ("DAFBUKU.DAT", "rb "))== NULL)
 
{
  
cputs ("File could not be opened! \ r \ n");
  
exit (1);
 
}
  
 
/ * Read record SCARA random * /
 
re = 'Y';
 
while (again == 'y' | | again == 'Y')
 
{
  
cputs ("\ r \ nNomor record of the data");
  
cputs ("you want to know:");
  
scanf ("% d", & nmr_record);
  
  
ofset_byte = (nmr_record-1) * sizeof (book);
  
fseek (pf, ofset_byte, SEEK_SET);
  
  
hasil_baca = fread (& user, sizeof (book), 1, pf);
  
if (hasil_baca == 0)
  
{
   
cprintf ("No record is not valid! \ r \ n");
   
continue; / * return kewhile * /
  
}
  
cprintf ("title:% s \ r \ n", buku.judul);
  
cprintf ("Author:% s \ r \ n", buku.pengarang);
  
cprintf ("Book number:% d \ r \ n", buku.jumlah);
  
  
cputs ("\ r \ nDo you want to look for more information (Y / T )?");
  
re = getche ();
 
}
 
/ * Close file * /
 
fclose (pf); }

0 comments:

Post a Comment

 

Home | Blogging Tips And Trick | Simple Blogspot HTML | All About Informations | Interesting Site | Simple And Accurate Site

Copyright © 2010-2012 Interesting info Template Design by Fajar Hudy Pratama