Yeah I believe I was able to rectify that by resetting the pointer before it is printed. But for some reason, everything is working except it is not writing the wastePile to the file but the tableau just fine. Any reason what would cause that?
I just editted my original post with the latest changes. So everything is working except when I tried to read in a previous game, says segmentatio fault. and its not writing to the previousGame texfile.
Now that wasteHome points to where the waste pile begins, you should set wastePtr = wasteHome before you call printWastePile and writeCards. Let me know if this fixes it.
Okay so that did help quite a bit, there is still some garbage getting spit out at the end. But the weird thing is that it doesn't write the wastePile to previousGame.txt
Okay up until now I had not looked at the writeCards function very closely.
But looking at it I can tell that counter variable goes from 0 to 6 every time.
And the else if on line 257 might need to be a regular if?
I am not altogether sure on your logic here, but I do know that line will never execute.
1 2 3 4 5 6 7 8 9
int counter = 0;
if( counter < 28 )
{
//I will do stuff :)
}
elseif( counter < 52 )
{
//I will never do stuff :(
}
My point is the else if is sad. It will never be able to execute its code :(
Yeah that did fix the write issue. Thanks for all the help. My logic was that after counter > 28 it would hit the else if statement. As far as printing out the wastePile, for some reason it outputs garbage at the end. Anyway, I really do appreciate all your help, I have banging my head on this last 3 days.
It is still printing garbage at the end of printing out the wastePile to the screen?
Could you edit your code post again? I will run it on my machine to see what it is doing.
I ran the code and did not see any garbage as far as I can tell on the screen.
Now in the file there is just an extra space at the end, but it printed off everything.
C:\Users\Kevin\Desktop\cplusplus.com\Reading Textfile using pointers>g++ cards.cpp
C:\Users\Kevin\Desktop\cplusplus.com\Reading Textfile using pointers>a
Enter filename to start game
cards.txt
Main Menu
---------
1. <N>ew Game
2. <P>revious Game
3. <Q>uit Game
4. ENTER SELECTION
n
Heart 1 Diamond 2 Heart 12 Diamond 12 Heart 11 Heart 10 Club 2
Heart 9 Club 7 Heart 7 Heart 6 Heart 5 Spade 12
Spade 13 Club 4 Spade 11 Spade 10 Spade 9
Spade 8 Diamond 1 Spade 6 Spade 5
Spade 3 Spade 2 Club 1
Club 13 Club 11
Heart 4
Waste Pile
----------
Heart 2 Club 10 Spade 1 Club 9 Diamond 4 Club 8 Diamond 3 Club 6 Heart 13 Diamond 9 Club 5 Club 3 Dia
mond 13 Diamond 11 Spade 7 Diamond 10 Diamond 8 Spade 4 Heart 8 Diamond 7 Heart 3 Diamond 6 Club 12 D
iamond 5
Main Menu
---------
1. <N>ew Game
2. <P>revious Game
3. <Q>uit Game
4. ENTER SELECTION
q
C:\Users\Kevin\Desktop\cplusplus.com\Reading Textfile using pointers>a
Enter filename to start game
cards.txt
Main Menu
---------
1. <N>ew Game
2. <P>revious Game
3. <Q>uit Game
4. ENTER SELECTION
n
Heart 1 Diamond 2 Heart 12 Diamond 12 Heart 11 Heart 10 Club 2
Heart 9 Club 7 Heart 7 Heart 6 Heart 5 Spade 12
Spade 13 Club 4 Spade 11 Spade 10 Spade 9
Spade 8 Diamond 1 Spade 6 Spade 5
Spade 3 Spade 2 Club 1
Club 13 Club 11
Heart 4
Waste Pile
----------
Heart 2 Club 10 Spade 1 Club 9 Diamond 4 Club 8 Diamond 3 Club 6 Heart 13 Diamond 9 Club 5 Club 3 Dia
mond 13 Diamond 11 Spade 7 Diamond 10 Diamond 8 Spade 4 Heart 8 Diamond 7 Heart 3 Diamond 6 Club 12 D
iamond 5
Main Menu
---------
1. <N>ew Game
2. <P>revious Game
3. <Q>uit Game
4. ENTER SELECTION
p
Enter previous game
cards.txt
Heart 1 Diamond 2 Heart 12 Diamond 12 Heart 11 Heart 10 Club 2
Heart 9 Club 7 Heart 7 Heart 6 Heart 5 Spade 12
Spade 13 Club 4 Spade 11 Spade 10 Spade 9
Spade 8 Diamond 1 Spade 6 Spade 5
Spade 3 Spade 2 Club 1
Club 13 Club 11
Heart 4
Waste Pile
----------
Heart 2 Club 10 Spade 1 Club 9 Diamond 4 Club 8 Diamond 3 Club 6 Heart 13 Diamond 9 Club 5 Club 3 Dia
mond 13 Diamond 11 Spade 7 Diamond 10 Diamond 8 Spade 4 Heart 8 Diamond 7 Heart 3 Diamond 6 Club 12 D
iamond 5
Main Menu
---------
1. <N>ew Game
2. <P>revious Game
3. <Q>uit Game
4. ENTER SELECTION
q
C:\Users\Kevin\Desktop\cplusplus.com\Reading Textfile using pointers>