C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28651
Number of posts: 94667

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Hello I need your help. Posted by robefortu on 12 May 2011 at 1:20 PM
#include <cstdlib>
#include <iostream>
#include <string.h>
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++)
Report
Re: Hello I need your help. Posted by msdnguide on 15 May 2011 at 11:23 AM
You can try http://www.msdnguide.info.
Msdnguide.info is one such website that provides technical support.

Thanks
Msdn Professional



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.