/* Interface for FixFile ADT */
/*
This is the implementation of an Abstract Data Type
to deal with files where all records have the same length
*/
#ifndef fixfile_h
#define fixfile_h
typedef struct FixFile *ptfile;
/*
This is the structure definition
the FixFile definition is not visible
to the user.
User should only make use of the pointer type
ptfile in the program. References to FixFile
may cause a syntax error.
*/
ptfile CreateFile(char filename[],int recsize,char mode[]);
/*
Creates an ADT of type FixFile. YOU MUST CALL THIS
FUNCTION TO INITIALIZE A POINTER TO THE FILE STRUCTURE.
parameters:
- name (or path) of file to be used
- recsize: the size of each record: do not use a value,
use sizeof(yourstructure) instead
- mode "w" is write
"r" is read you cannot read and write.
this function returns a pointer to the structure that will
handle operations with this file.
*/
void FileGetRecord(ptfile ptf,void *ptrecord);
/*
Reads a record from the file and positions the file to
read the next record.
Parameters:
- a pointer to the ADT that handles this file
- a (void) pointer to the structure where you want your
record to be read.
IMPORTANT:
THE RECORD STRUCTURE MUST BE IDENTICAL TO THE STRUCTURE
THAT WAS USED TO WRITE THE RECORD TO THE DISK SINCE NO
FORMATTING WILL TAKE PLACE.
*/
void FilePutRecord(ptfile adtpointer,void *recpointer);
/*
Writes a record to the file. The record is written in memory
image without any formatting.
Parameters:
- a pointer to the ADT structure handling this file
- a pointer to the structure from where you want to get
the data that will be written to the disk file.
*/
int FileEOF(ptfile ptf);
/*
Detects an End of File Condition.
Keep in mind that EOF happens when you try to read past the
last record. It DOES NOT happen when you read the last record.
This function returns a 1 in case EOF is detected
and returns a 0 otherwise.
*/
void FileClose(ptfile ptf);
/*
Closes the file and DESTROYS THE ADT
If you want to use the file again, you must
call CreateFile again.
The pointer will be DANGLING after calling this function.
*/
/*
useful functions
the functions below are not a part of the file ADT
but they are included here because they may be useful
*/
int yesno(char question[]);
/*
Prints a question and requests a yes or no answer.
If user repplies 'y', function returns a 1, otherwise
returns a zero.
*/
float ask(char question[]);
/*
Prints a question and prompts for a numeric value.
The value typed by the user is returned as a float.
*/
void askwords(char answer[],int max,char question[]);
/*
Prints a question and prompts the user for a string input.
the string is placed into the parameter "answer" which must
have enough space to accomodate the input.
The parameter "max" is used only as a reminder to the programmer
*/
#endif