>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 15:50:35 -0700 (PDT)
>
>
>--- 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();
>
>
Hey Mickey
yeah i tried all this but that number still appears. i changed the arrays to
size 10 and ran the program twice. the first time the text file was empty.
FIRST RUN
one 1
Two 2
three 3
four 4
Five 5
0
0
0
0
0
the second time it was full of the 2 arrays outputs but when its run the
second time the output is as follows
one 1
Two 2
three 3
four 4
Five 5
0 0
0 0
0 4202975 //whats this?
0 0
0
while ((infile >> Names[iCount]) && (infile >>
scores[iCount]))
{
iCount++;
}
//the number appears withe the above code.. thw while loop stops when iCount
becomes 7.. any ideas why?
infile.close();
outfile.open("HighScore.txt");
for(int i = 0;i<10;i++)
{
outfile << Names[i] << " ";
outfile << scores[i] <<" ";
outfile << "\n";
}
outfile.close();
and thanks for all the help i really appreciate all this
gav
>
>
>
>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/
_________________________________________________________________
Download Messenger. Join the im Initiative. Help make a difference today.
http://im.live.com/messenger/im/home/?source=TAGHM_APR07
To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/c-prog/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/c-prog/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/