Binary files!! Comparing...

Greetings!

I'm making a program to store the records of a school/university and i'm saving the data to a binary file.(Default binary file = database.inl, can be modified)

This is the structure.
1
2
3
4
5
6
7
8
9
10
11
struct Record
{
	unsigned int id;
	char nombre[15];
	char apellido[15];
	double gpa;
	unsigned int edad;
	char secundaria[20];
	char universidad[20];
	bool valido;
};

I collect the data from the user, but i need to check that the IDs is not stored already before continuing... that's where i'm stuck :/

1
2
3
4
5
6
7
8
9
  cout << "Numero de ID: ";
	cin >> tempStu.id; cout << endl;
	while(tempStu.id < 0)
	{...}
        record.open(output, ios::in | ios::binary);
	if(record.is_open())//If the file is new there's no need for the query-
	{
         //Here I'm having troubles getting the program to compare the whole .inl with tempStu.id
	}

And the easy part(when i finish collecting the data :P)
1
2
3
  record.open(output, ios::out | ios::app | ios::binary);
	record.write(reinterpret_cast<char*>(&tempStu), sizeof(record));
	record.close();


So I don't know how to go on, i have something in mind but is way too dumb, tedious and time-wasting that i guess there should be another way... Is there? Thanks beforehand!
When the program is running, you can keep track of the number of records in a variable.

You can initialise that record counter by checking the file size / record size. You check the file size with stat().
http://pubs.opengroup.org/onlinepubs/007908799/xsh/stat.html
Topic archived. No new replies allowed.