I am now moving in a different direction with this, Ive created a menu, and finished the text file but have come up with an error and a few warnings saying:
error C2065: 'hfPtr' : undeclared identifier
warning C4047 '=' : 'int ' differs in levels of indirection from 'struct _iobuf *'
warning C4047: '==' : 'int ' differs in levels of indirection from 'void *'
warning C4133: 'function' : incompatible types - from 'char [29]' to 'struct _iobuf *'
warning C4133: 'function' : incompatible types - from 'char [22]' to 'struct _iobuf *'
does anyone see what I've done wrong and anycoments on this code would be appreciated, thanks
Code:
#include <stdio.h>
/* hardwareData structure definition */
struct hardwareData {
int recordNum;
char toolname[20];
int quantity;
double cost;
}; /* end structure hardwareData */
/* prototypes */
int enterChoice( void );
void textFile( FILE *readPtr );
void updateRecord( FILE *fPtr );
void newRecord( FILE *fPtr );
void deleteRecord( FILE *fPtr );
int main()
{
FILE *hfPtr; /* hardware.dat file pointer */
int choice; /* user choice */
/* fopen opens file; exits if file cannot be opened */
if ((hfPtr = fopen( "hardware.dat", "rb+" )) == NULL ) {
printf( "File could not be opened.\n" );
} /* end if */
else {
/* enable user to specify action */
while (( choice = enterChoice()) != 5 ) {
switch ( choice ) {
/* create text file from record */
case 1:
textFile( hfPtr );
break;
/* update record */
case 2:
updateRecord( hfPtr );
break;
/* create record */
case 3:
newRecord ( hfPtr );
break;
/* delete existing record */
case 4:
deleteRecord ( hfPtr );
break;
/* display message if user does not enter valid choice */
default:
printf( "Incorrect choice\n" );
break;
} /* end switch */
} /* end while */
fclose( hfPtr ); /* fclose closes the file */
} /* end else */
return 0; /* indicate successful termination */
} /* end main */
/* create formated text for printing */
void textFile( FILE *readPtr )
{
FILE *writePtr; /* hardware.txt file pointer */
/* create hardwareData with default information */
struct hardwareData hardware = { 0, "", 0,0.0 };
/* fopen opens file; exits if file cannot be opened */
if ((hfPtr = fopen( "hardware.dat", "rb+" )) == NULL ) {
printf( "File could not be opened.\n" );
} /* end if */
else{
rewind( readPtr ); /* sets pointer to begining of file */
fprintf( "writePtr, %-6s%-10s%-8s%-8s\n",
"Record#", "Tool name", "Quantity", "Cost" );
/* copy all records from random-access file to text file */
while ( !feof( readPtr ) ) {
fread( &hardware, sizeof( struct hardwareData ),1, readPtr );
/* write single record to text file */
if ( hardware.recordNum != 0 ) {
fprintf( "%-6d%-16s%-11d%10.2f\n",
hardware.toolname, hardware.quantity, hardware.cost );
} /* end if */
} /* end while */
fclose( writePtr ); /* fclose closes file */
} /* end else */
} /* end function textrFile */