0

from this how do i make the data in the data file listed on my screen?
assuming i have already created and implement function for adding updating deleting records.
please help!!

    #include <stdio.h>


    struct videorecord {                              
       int rec_no;          /* account number */    
      char f_name[ 20 ];  /* film name */ 
      int noc_available; /* number of copies available */
      int rental_price; /* rental price */
      int Lday;/* day of loan*/
      int Lmonth;/* month of loan */
      int Lyear;   /* year of loan */ 
      int Rday;/* day of return*/
      int Rmonth;/* month of return */
      int Ryear;   /* year of return */ 
      }; /* end structure video record */                

   /* prototypes */
   int enterChoice( void );
   void textFile (FILE *readrecord);
   void newRecord( FILE *therecord );
   void deleteRecord( FILE *therecord );
   void updateRecord( FILE *therecord );





   int main()
   { 
      FILE *videoR; 
      int choice;  

    if ( ( videoR = fopen( "videoR.dat", "rb+" ) ) == NULL ) {
         printf( "File could not be opened.\n" );
      } /* end if */
      else { 


         while ( ( choice = enterChoice() ) != 5 ) { 

            switch ( choice ) { 
case 1:
               textFile ( videoR );
               break;

case 2:
                  newRecord( videoR );
                  break;

case 3:
                  deleteRecord( videoR );
                  break;

case 4:
                  updateRecord( videoR );
                 break;

default:
                 printf( "Incorrect choice\n" );
                  break;

            } 

         } 

         fclose( videoR ); 
      } 

      return 0; 

   } 



   void newRecord( FILE *therecord )
  { 
     /* create clientData with no information */
     struct videorecord record = { 0,"",0,0,0,0,0,0,0,0 };

     int recordnumber; /* account number */

     /* obtain number of account to create */
     printf( "Enter new record number: " );
     scanf( "%d", &recordnumber );

     /* move file pointer to correct record in file */              
     fseek( therecord, ( recordnumber - 1 ) * sizeof( struct videorecord ), 
            SEEK_SET );                                             

     /* read record from file */                            
     fread( &record, sizeof( struct videorecord ), 1, therecord );

    /* display error if account previously exists */
     if ( record.rec_no != 0 ) {
        printf( "record(%d) already contains information.Sorry this new record cannot be entered!\n",
                record.rec_no );
     } /* end if */
     else { /* create record */

        /* user enters last name, first name and balance */
        printf( "Enter  film-name no-copies-available rental-price:\n" );
        scanf( "%s%d%d", &record.f_name,&record.noc_available,&record.rental_price);

        printf( "Enter loan day-month-year (DD MM YYYY):\n" );
        scanf( "%d%d%d", &record.Lday,&record.Lmonth,&record.Lyear);

        printf( "Enter return day-month-year (DD MM YYYY):\n" );
        scanf( "%d%d%d",&record.Rday,&record.Rmonth,&record.Ryear);

        record.rec_no = recordnumber;

        /* move file pointer to correct record in file */
        fseek( therecord, ( record.rec_no - 1 ) *            
               sizeof( struct videorecord ), SEEK_SET );  

        /* insert record in file */                    
        fwrite( &record,                               
                sizeof( struct videorecord ), 1, therecord );
     } /* end else */

  } /* end function newRecord */

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by Adak
0

What i like to have, is a menu function where I can choose to:

1) display one record I've searched for
2) edit a record I've searched for
3) display a group of records - say video's with titles beginning with the letter A,etc. Pausing between screens.
4) display all records, pausing between screens.
5) give some stats on the database: number of records, compression per cent, etc.

What exactly do you want to add?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.