--- GLOGIC 20 <[EMAIL PROTECTED]> wrote:

> hey Mickey
> heres the code for writing to the file. they code
> seems to work fine when i 
> fill the txt file maually in notepad so that it has
> 10 names and scores in 
> it.. im so confused..
> 
> outfile.open("HighScore.txt");
> 
>         for (int i = 0;i<10;i++)
>         {
> 
> 
>          outfile << Names[i] << " ";
>          outfile << scores[i] <<" ";
>          outfile << "\n";
>         }
>         outfile.close();
> 
> 
> >From: Mickey Mathieson <[EMAIL PROTECTED]>
> >Reply-To: c-prog@yahoogroups.com
> >To: c-prog@yahoogroups.com
> >Subject: Re: [c-prog] text files again
> >Date: Mon, 9 Apr 2007 11:49:44 -0700 (PDT)
> >
> >
> >--- glogic_1 <[EMAIL PROTECTED]> wrote:
> >
> > > hey all
> > > what im trying to do is read in from a text file
> and
> > > place the values
> > > into relevent arrays. so for example the first
> time
> > > the game is played
> > > nothing would be read in because the file should
> be
> > > empty but the
> > > following code always puts  4203647 into the
> first
> > > location of the
> > > scores array. can anyone explain what this is?
> and
> > > how do i read in
> > > the info correctly?
> > >  while(!infile.eof() )
> > >
> > >                 {
> > >                         infile >> Names[iCount];
> > >
> > >                         infile >>
> scores[iCount];
> > >                         iCount++;
> > >
> > >                 }
> > >
> > > thanks
> > > gav


try this - it should work. After testing remove the
test value arrays.



 ofstream outfile("HighScore.txt",ios::out);

  char Names[6][20] = {"one", "Two", "three", "four",
"Five"};
  int scores[6] = {1, 2,3, 4,5};

  for (int i = 0;i<5;i++)
  {

    outfile << Names[i] << " ";
    outfile << scores[i] << " ";
    outfile << "\n";
  }

  outfile.close();

  int iCount = 0;
  ifstream Infile("HighScore.txt");

  while ((Infile >> Names[iCount]) && (Infile >>
scores[iCount]))
  {

    iCount++;

  }

  Infile.close();





Mickey M.
Construction Partner Inc.
http://www.constructionpartner.com


 
____________________________________________________________________________________
TV dinner still cooling? 
Check out "Tonight's Picks" on Yahoo! TV.
http://tv.yahoo.com/

Reply via email to