I am using window 7 as a operating system and i run this code in same os it shows the problem related to file handling but this problem wasn't occurred on xp and vista whats the problem ........????????????


try to run on win 7 and xp you will get the problem

#include<conio.h>
    #include<stdio.h>
    #include<iostream.h>
    #include<process.h>
    #include<dos.h>
    #include<time.h>
    #include<fstream.h>
    #include<string.h>
     
     
    class getInfo
    {
    int dep;
    int with;
    int bal;
    int year;
    int mon;
    int day;
    char des[100];
     
    public:
     
     
    getInfo()
    {
    dep =0;
    with =0;
    bal =0;
    year =0;
    mon =0;
    day =0;
     
    strcpy(des,"");
     
    }
     
    int year1()
    {
    return year;
    }
     
    int month1()
    {
    return mon;
    }
     
    int day1()
    {
    return day;
    }
     
     
     
    void gInfo()
    {
    int c;
    struct date a;
    getdate(&a);
     
    fflush(stdin);
    year=a.da_year;
    fflush(stdin);
    mon=a.da_mon;
    fflush(stdin);
    day=a.da_day;
     
    cout<<"1. Deposit."<<endl;
    cout<<"2. Withdraw."<<endl<<endl;
    cout<<"Enter your choice:";
    fflush(stdin);
    cin>>c;
     
    clrscr();
     
    cout<<"Enter the discription:";
    fflush(stdin);
    cin>>des;
     
    cout<<"Enter the Amount:";
     
     
     
    if(c==1)
    {
    fflush(stdin);
    cin>>dep;
     
    }
     
    else
    { fflush(stdin);
    cin>>with;
     
    }
    fflush(stdin);
    bal=balance(dep,with);
     
    }
     
     
    int balance(int dep,int with)
    {
    getInfo I4;
    fstream b;
    int s=0;
     
    b.open("myExpn.txt",ios::in);
    b.seekg(0,ios::cur);
     
    while(!b.read((char*)&I4,sizeof(I4))==0)
    {
    s=I4.bal;
    }
    //cout<<s;
    //getch();
    s=s+dep-with;
    b.close();
    return s;
     
     
    }
     
     
     
     
    void
    putInfo(int i)
    {
    gotoxy(2,i);cout<<year<<"/"<<mon<<"/"<<day;
    gotoxy(20,i);cout<<des;
    gotoxy(45,i);cout<<dep;
    gotoxy(58,i);cout<<with;
    gotoxy(69,i);cout<<bal;
    }
     
     
    };
     
     
    class file
    {
     
    public:
     
    void wFile()
     
    {
    getInfo I;
     
    fstream a;
    a.open("myExpn.txt",ios::app);
     
    I.gInfo();
     
     
     
    a.write((char*)&I,sizeof(I));
     
    a.close();
     
     
    }
     
     
    void rFile()
    {
     
    int j=3;
    getInfo I;
     
    fstream a;
    a.open("myExpn.txt",ios::in);
     
    a.seekg(0,ios::beg);
     
    window(1,3,80,25);
     
     
     
    while(!a.read((char*)&I,sizeof(I))==0)
    {
     
    I.putInfo(j);
    cout<<endl;
    j++;
     
    if(j==18)
    j=0;
    }
     
    a.close();
     
     
    }
     
     
     
     
     
     
     
    void search()
    {
     
     
    int j=3;
    int d;
    int c;
    int m;
    int y;
    int s=1;
    int m1;
    getInfo I;
    fstream a;
     
    cout<<"1. Search by date." <<endl;
    cout<<"2. Search by month."<<endl<<endl;
    cout<<"Enter your choice:";
    cin>>c;
     
    if(c==1)
    {
    cout<<"Enter the date in dd\mm\yyy:"<<endl;
    cin>>d>>m>>y;
    }
     
    if(c==2)
    {
    cout<<"Enter the month:";
    cin>>m1;
    }
     
     
     
     
     
     
     
     
    a.open("myExpn.txt",ios::in);
     
    a.seekg(0,ios::beg);
     
     
     
    //window(1,3,80,25);
    clrscr();
    show();
     
    while(!a.read((char*)&I,sizeof(I))==0)
    {
     
     
     
     
    if(c==1)
    {
     
     
    if(y==I.year1() && d==I.day1() && m==I.month1())
    {
     
    I.putInfo(j);
    cout<<endl;
    j++;
    s++;
     
    }
     
    else
    {
     
    if(m1==I.month1())
    {
    I.putInfo(j);
    cout<<endl;
    j++;
    s++;
    }
    }
     
     
     
    }
     
     
    }
     
    a.close();
     
    if(s==1)
    {
    clrscr();
    cout<<"No recotds are found.............";
    }
    }
     
     
    void show()
    {
    gotoxy(2,1);cout<<"Date";
    gotoxy(20,1);cout<<"description";
    gotoxy(45,1);cout<<"Deposit";
    gotoxy(58,1);cout<<"Withdraw";
    gotoxy(69,1);cout<<"Balance";
     
    }
     
     
     
     
     
    };
     
     
     
     
    void main()
    {
    file f;
    int c;
     
    //getInfo I;
    while(1)
    {
     
    window(1,1,80,25);
    textbackground(18);
    textcolor(5);
     
     
     
    clrscr();
     
     
     
    cout<<"1. Make a transection."<<endl;
    cout<<"2. Show all transection"<<endl;
    cout<<"3. search."<<endl;
    cout<<"4. Exit"<<endl;
     
    cout<<endl<<"Enter your choice:";
    cin>>c;
     
    clrscr();
     
    switch(c)
    {
    case 1:
    f.wFile();
    break;
    case 2:
     
    f.show();
    f.rFile();
    break;
     
    case 3:
     
    f.search();
    break;
     
     
    case 4:
    exit(0);
     
    }
     
     
    gotoxy(12,19);
    cout<<"Press any key to continue............";
     
    getch();
     
     
     
     
    }
     
     
     
     
    }

try to start the program as administrator:
1-right click on the exe
2-select run as administrator

This article has been dead for over six months. Start a new discussion instead.