Howdy, Stranger!

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

Categories

C Text File Problem

indeedindeed Member Posts: 1
I am trying to write an ATM simulator. Everything seems to work fine but I have an odd problem with text file.
Sorry for language but I couldn't translate it right now. First function writes the list made of accounts into text file.
Second one is reading data from there. I recall them when an operation is made. I can add new accounts without a problem but I cannot update the variables accunt struct consists. Actually they are all changed after an operation but they return to their first values after I write and read them from text files. Have been reading whole thing for hours but I don't know why it would do that. I didn't send whole program cause it was too long. I checked if i was calling reading before writing but no

[code]void yaz()
{
kayit=fopen("kayit.txt","w");
fprintf(kayit,"%d %d %d %d %d
",&yuzb,&ellib,&yirmib,&onb,&besb);
yhesap=ihesap;
while(yhesap!=NULL)
{
fprintf(kayit,"%d
%d
%d
%s
%s
",yhesap->hesapno,yhesap->sifre,yhesap->bakiye,yhesap->isim,yhesap->soyisim);
for(i=0;i<10;i++)
{
if(yhesap->ozet[i].gun!=0)
{
j=2;
fprintf(kayit,"%d
",j);
fprintf(kayit,"%d %d %d %d %d
",yhesap->ozet[i].gun,yhesap->ozet[i].ay,yhesap->ozet[i].yil,yhesap->ozet[i].islem,yhesap->ozet[i].islemtipi);
}
else
{
if(yhesap->ileri==NULL) j=200;
else j=100;
fprintf(kayit,"%d
",j);
break;
}
}
yhesap->sonislem=yhesap->ozet[0];
yhesap=yhesap->ileri;
}
fclose(kayit);
}


void yenile()
{
kayit=fopen("kayit.txt","r");
ihesap=NULL;
shesap=NULL;
yhesap=NULL;
k=0;
fscanf(kayit,"%d %d %d %d %d
",&yuzb,&ellib,&yirmib,&onb,&besb);
atmtoplam=yuzb*100+ellib*50+yirmib*20+onb*10+besb*5;
while(k!=17)
{
yhesap=(struct hesap*)malloc(sizeof(struct hesap));
fscanf(kayit,"%d
%d
%d
%s
%s
",&yhesap->hesapno,&yhesap->sifre,&yhesap->bakiye,&yhesap->isim,&yhesap->soyisim);
for(i=0;i<10;i++) yhesap->ozet[i].gun=0;
for(i=0;i<10;i++)
{
fscanf(kayit,"%d
",&j);
if(j==200) { k=17; break; }
if(j==100) break;
fscanf(kayit,"%d %d %d %d %d
",&yhesap->ozet[i].gun,&yhesap->ozet[i].ay,&yhesap->ozet[i].yil,&yhesap->ozet[i].islem,&yhesap->ozet[i].islemtipi);
}
yhesap->sonislem=yhesap->ozet[0];
yhesap->ileri=NULL;
if(ihesap==NULL) { ihesap=yhesap; shesap=ihesap; }
else { shesap->ileri=yhesap; shesap=yhesap; }
}
fclose(kayit);
}[/code]

Comments

  • LundinLundin Member Posts: 3,711
    Even without the foreign language, that code is completely unreadable. Please use indention and some blank lines in the code, and place only one statement on each line.
Sign In or Register to comment.