I am trying to create a program to log the medal tally of the cwg. However,I'm still getting wind of using binary files.
It seems as if nothing is being read from or written into them.
Below is my entire code.
It would be of help if somone could direct me as to what it is I've done wrong here.

#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<dos.h>

class contestant
{
    char name[20];
    char country[20];
    char sex[10];
    int age;

    int badminton;
    int archery;
    int swim;
    int wrestling;
    int boxing;
    int weightlft;
    int tennis;
    int shooting;
    int tt;
    int athletics;


  public:

  contestant()
  {     badminton=0;
    archery=0;
    swim=0;
    wrestling=0;
    boxing=0;
    weightlft=0;
    tennis=0;
    shooting=0;
    tt=0;
    athletics=0;
    id=0;
  }

    static int ind;
    static int pak;
    static int aust;
    static int can;
    static int eng;
    static int nz;
    static int mal;
    static int rsa;
    static int scot;
    static int jam;
    static int kenya;
    static int sing;
    static int nig;
    static int cyprus;
    static int wales;

  int bad()
      {return(badminton);}

  int arc()
    {return archery;}

  int sw()
      {return swim;}

  int wrs()
    {return wrestling;}

  int box()
    {return boxing;}

  int wgt()
    {return weightlft;}

  int ten()
    {return tennis;}

  int shoot()
    {return shooting;}

  int ping()
    {return tt;}

  int ath()
    {return athletics;}

  int id;
  void reg();
  void events();
  void name_print()
      {puts(name);}

  void tally();
};


void contestant::tally()
  {      if(!strcmp(country,"India")) ind++;
      else if(!strcpy(country,"Pakistan")) pak++;
      else if(!strcmp(country,"Australia")) aust++;
      else if(!strcmp(country,"Canada")) can++ ;
      else if(!strcmp(country,"England")) eng++;
      else if(!strcmp(country,"New Zealand")) nz++;
      else if(!strcmp(country,"Malaysia")) mal++;
      else if(!strcmp(country,"South Africa")) rsa++;
      else if(!strcmp(country,"Scotland")) scot++;
      else if(!strcmp(country,"Jamaica")) jam++;
      else if(!strcmp(country,"Kenya")) jam++;
      else if(!strcmp(country,"Singapore")) sing++;
      else if(!strcmp(country,"Nigeria")) nig++;
      else if(!strcmp(country,"Cyprus")) cyprus++;
      else if(!strcmp(country,"Wales")) wales++;
  }

const count_ry=15;
int contestant::ind=0;
int contestant::pak=0;
int contestant::aust=0;
int contestant::can=0;
int contestant::eng=0;
int contestant::nz=0;
int contestant::mal=0;
int contestant::rsa=0;
int contestant::scot=0;
int contestant::jam=0;
int contestant::kenya=0;
int contestant::sing=0;
int contestant::nig=0;
int contestant::cyprus=0;
int contestant::wales=0;

void contestant::reg()
{
    clrscr();
    int option=0;

    grr:
    cout<<"\nSelect your country:";
    cout<<"\n\t1--India\n\t2--Pakistan\n\t3--Australia\n\t4--Canada\n\t5--England";
    cout<<"\n\t6--New Zealand\n\t7--Malaysia\n\t8--South Africa\n\t9--Scotland\n\t10--Jamaica";
    cout<<"\n\t11--Kenya\n\t12--Singapore\n\t13--Nigeria\n\t14--Cyprus\n\t15--Wales\n\n";
    cin>>option;

    switch (option)
        {case 1: strcpy(country,"India");
            break;
        case 2: strcpy(country,"Pakistan");
            break;
        case 3: strcpy(country,"Australia");
            break;
        case 4: strcpy(country,"Canada");
            break;
        case 5: strcpy(country,"England");
            break;
        case 6: strcpy(country,"New Zealand");
            break;
        case 7: strcpy(country,"Malaysia");
            break;
        case 8:    strcpy(country,"South Africa");
            break;
        case 9: strcpy(country,"Scotland");
            break;
        case 10: strcpy(country,"Jamaica");
            break;
        case 11: strcpy(country,"Kenya");
            break;
        case 12: strcpy(country,"Singapore");
            break;
        case 13: strcpy(country,"Nigeria");
            break;
        case 14: strcpy(country,"Cyprus");
            break;
        case 15:strcpy(country,"Wales");
            break;
        default: cout<<"\n\nSorry, not a contesting country.";
            goto grr;
    }

    cout<<"\n\nEnter name: ";
    gets(name);

    cout<<"Enter player id: ";
    cin>>id;

    cout<<"\nAge: ";
    cin>>age;

    cout<<"\nSex: ";
    gets(sex);

    cout<<"\nSelect participating events:";
    events();

    cout<<"\n\nThank you for registering. India wishes you a pleasant stay and a memorable Commonwealth Games. =) ";
}

void contestant::events()
{
    int o=-1;
    cout<<"\nSelect participating events [Note:enter 0 to exit]:\n1--Badminton\n2--Archery\n3--Hockey\n4--Wrestling\n5--Boxing\n6--Weightlft\n7--Tennis\n8--Shooting\n9--tt\n10--Athletics\n\n\t";

    while(o)
    {
        cin>>o;
        switch(o)
          {    case 0: break;
            case 1: badminton=1; break;
            case 2: archery=1; break;
            case 3: swim=1;  break;
            case 4: wrestling=1; break;
            case 5: boxing=1; break;
            case 6: weightlft=1; break;
            case 7: tennis=1; break;
            case 8: shooting=1; break;
            case 9: tt=1; break;
            case 10: athletics=1; break;
            default: cout<<"\n\nSorry, game invalid! =(";
          }

    }
}

void games()
{
    ifstream cwg("CWG.dat",ios::binary);
    contestant champ;
    int winr;


    //Badminton
        {clrscr();
        cout<<"\t\t\t\tBADMINTON";
        cwg.seekg(ios::beg);
        cout<<"\nThe following contestants are participating\n\n";
        while(cwg.read((char*) &champ, sizeof(champ)))
            {if(champ.bad())
                {cout<<champ.id<<" : ";
                champ.name_print();
                }
            }
        cout<<"\n\nEnter winner's id:";
        cin>>winr;
        cwg.seekg(ios::beg);
        while(cwg.read((char*) &champ, sizeof(champ)))
            {if(champ.id==winr)
                {champ.tally();}
            }
        }


    //archery
        {clrscr();
        cout<<"\t\t\t\tARCHERY";
        cwg.seekg(ios::beg);
        cout<<"\nThe following contestants are participating\n";
        while(cwg.read((char*) &champ, sizeof(champ)))
            {if(champ.arc())
                {cout<<champ.id<<" : ";
                champ.name_print();
                }
            }
        cout<<"\n\nEnter winner's id:";
        cin>>winr;
        cwg.seekg(ios::beg);
        while(cwg.read((char*) &champ, sizeof(champ)))
            {if(champ.id==winr)
                {champ.tally();}
            }
        }


    //swimming
        {clrscr();
        cout<<"\t\t\t\tSWIMMING";
        cwg.seekg(ios::beg);
        cout<<"\nThe following contestants are participating\n";
        while(cwg.read((char*) &champ, sizeof(champ)))
            {if(champ.sw())
                {cout<<champ.id<<" : ";
                champ.name_print();
                }
            }
        cout<<"\n\nEnter winner's id:";
        cin>>winr;
        cwg.seekg(ios::beg);
        while(cwg.read((char*) &champ, sizeof(champ)))
            {if(champ.id==winr)
                {champ.tally();}
            }
        }


    //wrestling
        {clrscr();
        cout<<"\t\t\t\tWRESTLING";
        cwg.seekg(ios::beg);
        cout<<"\nThe following contestants are participating\n";
        while(cwg.read((char*) &champ, sizeof(champ)))
            {if(champ.wrs())
                {cout<<champ.id<<" : ";
                champ.name_print();
                }
            }
        cout<<"\n\nEnter winner's id:";
        cin>>winr;
        cwg.seekg(ios::beg);
        while(cwg.read((char*) &champ, sizeof(champ)))
            {if(champ.id==winr)
                {champ.tally();}
            }
        }


    //boxing
        {clrscr();
        cout<<"\t\t\t\tBOXING";
        cwg.seekg(ios::beg);
        cout<<"\nThe following contestants are participating\n";
        while(cwg.read((char*) &champ, sizeof(champ)))
            {if(champ.box())
                {cout<<champ.id<<" : ";
                champ.name_print();
                }
            }
        cout<<"\n\nEnter winner's id:";
        cin>>winr;
        cwg.seekg(ios::beg);
        while(cwg.read((char*) &champ, sizeof(champ)))
            {if(champ.id==winr)
                {champ.tally();}
            }
        }


    //weightlft
        {clrscr();
        cout<<"\t\t\t\tWEIGHT LIFTING";
        cwg.seekg(ios::beg);
        cout<<"\nThe following contestants are participating\n";
        while(cwg.read((char*) &champ, sizeof(champ)))
            {if(champ.wgt())
                {cout<<champ.id<<" : ";
                champ.name_print();
                }
            }
        cout<<"\n\nEnter winner's id:";
        cin>>winr;
        cwg.seekg(ios::beg);
        while(cwg.read((char*) &champ, sizeof(champ)))
            {if(champ.id==winr)
                {champ.tally();}
            }
        }


    //tennis
        {clrscr();
        cout<<"\t\t\t\tTENNIS";
        cwg.seekg(ios::beg);
        cout<<"\nThe following contestants are participating\n";
        while(cwg.read((char*) &champ, sizeof(champ)))
            {if(champ.ten())
                {cout<<champ.id<<" : ";
                champ.name_print();
                }
            }
        cout<<"\n\nEnter winner's id:";
        cin>>winr;
        cwg.seekg(ios::beg);
        while(cwg.read((char*) &champ, sizeof(champ)))
            {if(champ.id==winr)
                {champ.tally();}
            }
        }


    //shooting
        {clrscr();
        cout<<"\t\t\t\tSHOOTING";
        cwg.seekg(ios::beg);
        cout<<"\nThe following contestants are participating\n";
        while(cwg.read((char*) &champ, sizeof(champ)))
            {if(champ.shoot())
                {cout<<champ.id<<" : ";
                champ.name_print();
                }
            }
        cout<<"\n\nEnter winner's id:";
        cin>>winr;
        cwg.seekg(ios::beg);
        while(cwg.read((char*) &champ, sizeof(champ)))
            {if(champ.id==winr)
                {champ.tally();}
            }
        }


    //tt
        {clrscr();
        cout<<"\t\t\t\tTABLE TENNIS";
        cwg.seekg(ios::beg);
        cout<<"\nThe following contestants are participating\n";
        while(cwg.read((char*) &champ, sizeof(champ)))
            {if(champ.ping())
                {cout<<champ.id<<" : ";
                champ.name_print();
                }
            }
        cout<<"\n\nEnter winner's id:";
        cin>>winr;
        cwg.seekg(ios::beg);
        while(cwg.read((char*) &champ, sizeof(champ)))
            {if(champ.id==winr)
                {champ.tally();}
            }
        }


    //athletics
        {clrscr();
        cout<<"\t\t\t\tATHLETICS";
        cwg.seekg(ios::beg);
        cout<<"\nThe following contestants are participating\n";
        while(cwg.read((char*) &champ, sizeof(champ)))
            {if(champ.ath())
                {cout<<champ.id<<" : ";
                champ.name_print();
                }
            }
        cout<<"\n\nEnter winner's id:";
        cin>>winr;
        cwg.seekg(ios::beg);
        while(cwg.read((char*) &champ, sizeof(champ)))
            {if(champ.id==winr)
                {champ.tally();}
            }
        }

    cwg.close();
}

void results()
{
    cout<<"\n\nThe results are::\n\n";
    for(int i=0,j=0;i<count_ry;j++)
        {
        if(contestant::ind==j)
              {cout<<"\t"<<count_ry-i<<":\tINDIA\t"<<j<<"Gold medals\n";
            i++;}

        else if(contestant::pak==j)
              {cout<<"\t"<<count_ry-i<<":\tPAKISTAN\t"<<j<<"Gold medals\n";
            i++;}

        else if(contestant::aust==j)
              {cout<<"\t"<<count_ry-i<<":\tAUSTRALIA\t"<<j<<"Gold medals\n";
            i++;}

        else if(contestant::can==j)
              {cout<<"\t"<<count_ry-i<<":\tCANADA\t"<<j<<"Gold medals\n";
            i++;}

        else if(contestant::eng==j)
              {cout<<"\t"<<count_ry-i<<":\tENGLAND\t"<<j<<"Gold medals\n";
            i++;}

        else if(contestant::nz==j)
              {cout<<"\t"<<count_ry-i<<":\tNEW ZEALAND\t"<<j<<"Gold medals\n";
            i++;}

        else if(contestant::mal==j)
              {cout<<"\t"<<count_ry-i<<":\tMALAYSIA\t"<<j<<"Gold medals\n";
            i++;}

        else if(contestant::rsa==j)
              {cout<<"\t"<<count_ry-i<<":\tREPUBLIC OF SOUTH AFRICA\t"<<j<<"Gold medals\n";
            i++;}

        else if(contestant::scot==j)
              {cout<<"\t"<<count_ry-i<<":\tSCOTLAND\t"<<j<<"Gold medals\n";
            i++;}

        else if(contestant::jam==j)
              {cout<<"\t"<<count_ry-i<<":\tJAMAICA\t"<<j<<"Gold medals\n";
            i++;}

        else if(contestant::kenya==j)
              {cout<<"\t"<<count_ry-i<<":\tKENYA\t"<<j<<"Gold medals\n";
            i++;}

        else if(contestant::sing==j)
              {cout<<"\t"<<count_ry-i<<":\tSINGAPORE\t"<<j<<"Gold medals\n";
            i++;}

        else if(contestant::nig==j)
              {cout<<"\t"<<count_ry-i<<":\tNIGERIA\t"<<j<<"Gold medals\n";
            i++;}

        else if(contestant::cyprus==j)
              {cout<<"\t"<<count_ry-i<<":\tCYPRUS\t"<<j<<"Gold medals\n";
            i++;}

        else if(contestant::wales==j)
              {cout<<"\t"<<count_ry-i<<":\tWALES\t"<<j<<"Gold medals\n";
            i++;}
        }
}

void main()
{
    clrscr();
    fstream cwg("CWG.dat",ios::binary|ios::in|ios::out);
    contestant ppt;
    int option=1;


    cout<<"Delhi";
    delay(200);
    cout<<"\n03 October 2010:\n";
    delay(200);
    cout<<"Day 0:Commonwealth Games Final Registration";
    delay(1200);

    while(option)
    {    cout<<"\n\nNAMASTE!!\n\nWelcome to CWG Delhi 2010!\n\n\tPess 1 to register\n\tPress 0 to proceed with the games!";
        cin>>option;
        if(option)
        {ppt.reg(); }

        cwg.write((char*) &ppt,sizeof(ppt));
        clrscr();
    }
    cwg.close();

    cout<<"\n\n\t\t\tLET THE GAMES BEGIN!! =)\n";
    games();

    clrscr();
    cout<<"Delhi";
    delay(200);
    cout<<"\n14 October 2010:\n";
    delay(200);
    cout<<"Day 10: Commomwealth Games Wind Up\n\n\t\t\tPress any key for results";
    getche();
    results();
    getche();
}

As for the text marked red,
I wanted to highlight the use of { } braces.
I'm not sure whether that is allowed. I'm using borland cpp nd it didn't show any errors on compilation.

This is too long code and is not inside a code tag...

Anyway, it seems that people are having problem with read/write file in Borland. Not sure if this link would help...

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