Hi. I am creating a binary file that saves up to 5 data and everytime a new data saves the old (last) saved data will be deleted. I am having problem creating the c program to delete the last saved data.. this is what I have so far..I need help
insert
Code:
#include <stdio.h>
// Symbolic constants
#define BIN_FILE "data.bin"
#define NUM_VALUES 5 // number of values to read from binary file
// For computed values
#define NUM 5 // number of computed values
// The following are indexes into the array
// containing computed values
#define VIX 0
#define CoIX 1
#define QIX 2
#define tIX 3
#define CIIX 4
// function prototypes
void STOREDDATA(FILE *, double *);
/*---------------------------------------------------------------------
Function: main
Description: Opens a binary file and calls STOREDDATA to save the initial concentration of the reactor volume,the
concentration of the inlet flow, the volumetric flow rate of the streams and the total run time of the process values into the file
------------------------------------------------------------------------*/
void main(void)
{
// Variable declarations
FILE *fp; // File pointer for binary file
double outputVals[NUM];
// Open the file
fp = fopen(BIN_FILE, "rb");
if(fp == NULL)
printf("Cannot open binary file %s\n", BIN_FILE);
else
{
STOREDDATA(fp, outputVals);
// Display the results
printf("Analysis of file data gives: \n");
printf(" initial concentration of the reactor volume: %.3f\n", outputVals[CoIX]);
printf(" volume of the reactor: %.3f\n", outputVals[VIX]);
printf(" concentration of the inlet flow: %.3f\n", outputVals[CIIX]);
printf(" the volumetric flow rate of the streams: %.3f\n", outputVals[QIX]);
printf(" total run time: %.3f\n", outputVals[tIX]);
fclose(fp);
}
}
/*-----------------------------------------------------------------------
Function: STOREDDATA
Parameters:
fp - file pointer for input binary file
outPt - pointer to array for storing compute values.
Description: Reads all data values into an array and scans the data
within the array to compute 5 outputs
------------------------------------------------------------------------*/
void STOREDDATA(FILE *fp, double *outPt)
{
// Declarations
double Co; //initial concentration of the reactor volume
double V;//volume of the reactor
double CI; // concentration of the inlet flow
double Q; //volumetric flow rate of the streams
double t; //total run time
double val; // value read from the file
double values[NUM_VALUES]; // Cannot read more than MAX_NUM_VALUES
int ix; // Indexes into array and counts number of values read
// Read in values into the array
rewind(fp); // start at the beginning of the file
fread(values, sizeof(double),NUM_VALUES,fp);
}