#include <iostream>
#include <fstream>

using namespace std;

struct student
{
	int indeks;
	int godina;
	char ime[50];
	char prezime[50];
};


void pisanje()
{
	student studenti[] = {
		{ 25, 2002, "Pera", "Peric" },
		{ 31, 2001, "Zika", "Zikic" },
		{ 17, 1999, "Persa", "Persic" }
	};
	
	ofstream f( "studenti.dat", ios::binary );
	for( int i=0; i<sizeof(studenti)/sizeof(student); i++ )
		f.write( (char*)&(studenti[i]), sizeof(student));
}

void citanje( int i )
{
	student s;	
	ifstream f( "studenti.dat", ios::binary );
	f.seekg( i * sizeof(student));
	f.read( (char*)&s, sizeof(student));
	if( f ){
		cout 
			<< s.indeks << ' ' 
			<< s.godina << ' '
			<< s.ime << ' '
			<< s.prezime << endl;
	}
	else
		cout << "Ne postoji " << i << ". student." << endl;
}

main()
{
	pisanje();
	citanje(2);
	citanje(1);
	citanje(7);
	return 0;
}

/*
17 1999 Persa Persic
31 2001 Zika Zikic
Ne postoji 7. student.
*/