Hello I need your help. - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Hello I need your help.

robeforturobefortu Posts: 1Member
#include
#include
#include
using namespace std;

struct t_alunno
{
string nome;
string codice;
int eta;
};
t_alunno alunno;
t_alunno buffer;
FILE * fp;
int nrecord;
int i;
bool trovato;
int scelta;
int posizione;
string codicex;

void cazzo();
void caricamento();
void stampa();
void modifica();
void cancellazione_logica();

int main()
{

caricamento();
stampa();

system("PAUSE");
return EXIT_SUCCESS;
}

void modifica()
{
fp=fopen("prova.dat","wr");
cin>>codicex;
nrecord=sizeof(alunno);
i=0;
trovato = false;
while ((i<=nrecord)&&(!trovato))
{
if (codicex==alunno.codice)
{
fread(&buffer,sizeof(alunno.codice),1,fp);
posizione=i;
trovato=true;
cout<<"Vuoi modificare? 0=NO 1=SI";
cin>>scelta;
if (scelta==1)
{
cin>>alunno.eta;
fwrite(&buffer,nrecord,1,fp);
}
}
i++;
}
fclose(fp);
}

void cancellazione_logica()
{
fp=fopen("prova.dat","wr");
cin>>codicex;
nrecord=sizeof(alunno);
i=0;
trovato = false;
while ((i<=nrecord)&&(!trovato))
{
if (codicex==alunno.codice)
{
posizione=i;
trovato=true;
cout<<"Vuoi eliminare? 0=NO 1=SI";
cin>>scelta;
if (scelta==1)
{
alunno.codice="**";
fwrite(&buffer,nrecord,1,fp);
}
}
i++;
}
fclose(fp);
}

void caricamento()
{
fp=fopen("prova.txt","wr");
nrecord=sizeof(alunno);
//cazzo();
cin>>alunno.nome;
cin>>alunno.eta;
cin>>alunno.codice;
fwrite(&alunno,nrecord+1,1,fp);
fclose(fp);
}

void stampa()
{
fp=fopen("prova.txt","wr");
nrecord=sizeof(alunno);
//cazzo();
for (i=0;i<=nrecord;i++)
{
fread(&alunno,i,1,fp);
if (alunno.codice!="**")
{
cout<<alunno.nome;
cout<<alunno.eta;
cout<<alunno.codice<<endl;
}
}
fclose(fp);
}

void cazzo()
{
nrecord=0;
fp=fopen("prova.dat","r");
while(!feof)
{
fseek(fp,nrecord,1);
nrecord=nrecord+1;
}
fclose(fp);
}

what's wrong with this program ?
I suppose that the proble is sizeof, so i tried cazzo(), but at the star it goes in loop. where is the problem ?
(I used dev c++)

Comments

Sign In or Register to comment.