I am new to programming and on our current assignment we have to effectively create a database to store various pieces of information in a struct.
I have created so far an add file function(works well)
main()
print all to screen(works well) and I am now working on the display record function which utilizes a search function to display the records.
The problems I am having are my search Function prints the information I want twice to the console instead of just once. I also need to pass the information when found over to my display record function to be able to display it on the console screen.....
I am pretty desperate and have read as much as I can but the way our tutor makes us program is quite different from most of the resources I can find on the net and my understanding is still very limited.
clrscr();
cout << "You have selected the delete/Undelete Record Function " << endl;
switchFunction();
getch();
}
//---------------------------------------------------------------------------
//void updateRecord();
//Purpose:
//Intput:
//Output:
//----------------------------------------------------------------------------
void updateRecord()
{
clrscr();
cout << " You have selected the update Record Function update" << endl;
switchFunction();
getch();
}
//---------------------------------------------------------------------------
//void displayRecord()
//Purpose:
//Intput:
//Output:
//----------------------------------------------------------------------------
void displayRecord()
{
int returnFromFunction;
char itemToFind[ 12 ];
Record temp;
cout << "Please enter the record you would like to search: ";
cin >> itemToFind;
search( itemToFind );
MyFile.open( FILE_PATH, ios :: binary | ios :: in );
MyFile.read(( char* ) &temp, sizeof( Record ) );
returnFromFunction = search( itemToFind );
if ( returnFromFunction == -1 )
{
MyFile.seekp(0, ios :: beg);
cout << temp.firstName << temp.age;
cout << "boo";
}
else
cout << "No Records found press any key to continue";
getch();
}
Rather than have each operation manipulate data in the file, it is better to read the file into memory and manipulate the memory representation, then write the file at the end.
You can then use conventional data structures to manage records.
Also, that will allow you to get rid of that global file thing. Never use global variables unless there's a very good reason to or there's no alternative.