Can anyone help me make a pseudocode for this function....cause its really difficult:'(

int updateRecord( FILE *fPtr )
{ 
   int account;        /* account number */
   double transaction; /* transaction amount */

   /* create clientData with no information */
   struct clientData c = { 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( &c, sizeof( struct clientData ), 1, fPtr );

   /* display error if account does not exist */
   if ( c.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", 
         c.acctNum, c.lastName, 
         c.firstName, c.balance );
      
      /* request transaction amount from user */ 
      printf( "Enter charge ( + ) or payment ( - ): " );
      scanf( "%lf", &transaction );
      c.balance += transaction; /* update record balance */
      
      printf( "\t\t%-6d   %-16s   %-11s   %10.2f\n", 
         c.acctNum, c.lastName, 
         c.firstName, c.balance );
      
      /* move file pointer to correct record in file */
      fseek( fPtr, ( account - 1 ) * sizeof( struct clientData ), SEEK_SET );

      /* write updated record over old record in file */
      fwrite( &c, sizeof( struct clientData ), 1, fPtr );
   } /* end else */

} /* end function updateRecord */

/* delete an existing record */

Dani AI

Generated

This function’s purpose is to locate a fixed-size record in a file, show the current values, accept a numeric transaction, update the balance, and write the updated record back in place. Common omissions to avoid: not checking the file handle, not validating user input, and not checking read/write return values.

function UpdateRecord(file):
    if file is not open:
        return error

    prompt for account_number (expected 1..100)
    if account_number is invalid:
        print "invalid account" and return

    offset = (account_number - 1) * RECORD_SIZE
    seek file to offset
    record = read RECORD_SIZE bytes
    if read failed:
        print "read error" and return

    if record indicates "no data" (acctNum == 0):
        print "Loan #N has no information" and return

    display record summary (acctNum, lastName, firstName, balance)

    prompt for transaction amount (+ charge, - payment)
    if transaction input invalid:
        print "invalid transaction" and return

    record.balance = record.balance + transaction
    display updated summary

    seek file to offset
    write record back to file (overwrite)
    if write failed:
        print "write error" and return

    flush file buffers (ensure data on disk)
    return success

Practical notes: always validate input (check scanf/parse return values), verify seeks/reads/writes succeed, and avoid assuming fixed console input formatting. If data integrity matters, consider writing the updated record to a temporary file or locking the file during the update to prevent concurrent corruption. Use a named constant for RECORD_SIZE so the offset math is clear and maintainable.

This approach follows ’s advice to start with pseudocode and include error handling. Copying comments as suggested produces something quick, but an explicit step list is clearer. ’s pointer to algorithm resources is useful background; ’s remark isn’t helpful to the task.

Recommended Answers

All 4 Replies

So you wrote a code that you don't understand? That's funny :)

Copy/paste all commentaries from the source: it's your desired pseudocode ;)...

commented: Indeed, if they'd written the pseudo-code first, it would become the comments! +21

Perhaps this may help ? here :)

This is not a difficult function nor is it well written.
I would suggest starting with pseudo code (including error handling) and then writing the actual code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.