Can anyone fix my code especially in the updateRecord function because instead of updating,data remains the same.

int newRecord( FILE *fPtr )
{ 
   /* create clientData with default information */
   struct clientData client = { 0, "", "", 0.0 };

   int accountNum; /* account number */

   /* obtain number of account to create */
   printf( "Enter new loan number ( 1 - 100 ): " );
   scanf( "%d", &accountNum );

   /* move file pointer to correct record in file */
   fseek( fPtr, ( accountNum - 1 ) * sizeof( struct clientData ), SEEK_SET );

   /* read record from file */
   fread( &client, sizeof( struct clientData ), 1, fPtr );

   /* display error if account already exists */
   if ( client.acctNum != 0 ) {
      printf( "Loan #%d already contains information.\n",client.acctNum );
   } /* end if */
   else { /* create record */

      /* user enters last name, first name and balance */
    
      printf( "  Enter lastname, firstname, balance\n" );
      scanf("%s%s%lf", &client.lastName, &client.firstName, &client.balance );

      client.acctNum = accountNum;
      
      /* move file pointer to correct record in file */
      fseek( fPtr, ( client.acctNum - 1 ) * sizeof( struct clientData ), SEEK_SET );

      /* insert record in file */
      fwrite( &client, sizeof( struct clientData ), 1, fPtr );
   } /* end else */

} /* end function newRecord */

/* enable user to input menu choice */


int updateRecord( FILE *fPtr )
{ 
   int account,choice,cli,accountNum;
   char c[15],cl[15];        /* account number */
   double transaction; /* transaction amount */

   /* create clientData with no information */
   struct clientData client = {0,"", "", 0.0 };

   /* obtain number of account to update */
   printf( "Enter Loan No. to update ( 1 - 100 ): " );
   scanf( "%d", &account );

   /* move file pointer to correct record in file */
   fseek( fPtr, ( account - 1 ) * sizeof( struct clientData ), SEEK_SET );

   /* read record from file */
   fread( &client, sizeof( struct clientData ), 1, fPtr );

   /* display error if account does not exist */
   if ( client.acctNum == 0 ) {
      printf( "Loan #%d has no information.\n", account );
   } /* end if */
   else 
        { /* update record */
        printf( "\t\t%-6d   %-16s   %-11s   %10.2f\n\n", 
        client.acctNum, client.lastName, 
        client.firstName, client.balance );
    
 fseek( lfPtr, ( accountNum - 1 ) * sizeof( struct clientData ), SEEK_SET );

   /* read record from file */
   fread( &client, sizeof( struct clientData ), 1, lfPtr );
    
  /* user enters last name, first name and balance */
      printf( "  Enter lastname, firstname, balance\n" );
      scanf("%s%s%lf", &client.lastName, &client.firstName, &client.balance );

      client.acctNum = accountNum;
      
      /* move file pointer to correct record in file */
      fseek( lfPtr, ( client.acctNum - 1 ) * sizeof( struct clientData ), SEEK_SET );

      /* insert record in file */
      fwrite( &client, sizeof( struct clientData ), 1, lfPtr );
    /* end else */

}
This article has been dead for over six months. Start a new discussion instead.