// tema.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "tema.h" #include "windows.h" //Fisier::Fisier() //{ //} Fisier::Fisier(char* FileName) { if (FileName!=NULL) { pf=fopen(FileName,"w+b"); fseek(pf,0,SEEK_END); FileSize=ftell(pf); fseek(pf,0,SEEK_SET); if (FileSize>0) {IsEOF=false;} else {IsEOF=true;}; } else MessageBox(NULL,"Pointer to file is null",NULL,1); } Fisier::~Fisier() { if (pf!=NULL) fclose(pf); } int & Fisier::operator [](int pozitie) { fseek(pf,pozitie*4,SEEK_SET); int articol; fread(&articol,4,1,pf); int CurrentPosition=ftell(pf); if (CurrentPositionpf!=NULL) fwrite(&a,4,1,pf->pf); } Pozitie::operator int*() { int a; if (pf->IsEOF==false) { return &pf[0][1]; } else return 0; } int main(int argc, char* argv[]) { Fisier* ob1=new Fisier("test.dat"); Pozitie ob2(ob1); int valoare; do { printf("%s","Dati o noua valoare pana dati valoarea 0: "); scanf("%i",&valoare); if (valoare==0) break; ob2=valoare; } while (true); do { printf("%s","Introduceti pozitia pentru inregistrarea din fisier pana introduceti -1 : "); scanf("%d",&valoare); if (valoare==-1) break; printf ("Valoarea este %d\n",ob2.pf[0][valoare]); } while (true); return 0; }