Instead of assuming, check, e.g., while reading.Originally Posted by esbo
The right alternative to having printf statements for debugging is to use a debugger. Assertions should be used to document pre-conditions, post-conditions and assumptions in your code for which a violation indicates a programming error. Hence, using an assertion to check user input is silly: invalid user input is not a programming error. Rather, failure to correctly handle invalid user input is a programming error.Originally Posted by esbo
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
He program is a bit of a mess to be honest but I think it used to work OK, at least it didn't crash.
Normally when it finds a new game if see debug code like this.
Code:Tablevar2 <#2439431Speed> tabname<#2439431Speed> finished loop <K.I.N.G.> SEATED adding PLAYER <K.I.N.G.> finished loop <Pyran1a> SEATED adding PLAYER <Pyran1a> finished loop <Urkarian> SEATED adding PLAYER <Urkarian> finished loop <collocollo> SEATED adding PLAYER <collocollo> finished loop <fxm341> SEATED adding PLAYER <fxm341> finished loop <gamas824> SEATED adding PLAYER <gamas824> finished loop <george_shrub> SEATED adding PLAYER <george_shrub> finished loop <gordonebula> SEATED adding PLAYER <gordonebula> finished loop <moliner0001> SEATED adding PLAYER <moliner0001> debug1 <0.05 USD].> debug12 var1 <gamas824 posts small blind [$0.05 USD].> debug12aa
But after a point I instead see debug like this which indicates things have got out of step.
Code:int <> Hint <#Game No : 11600365239 > Hint <***** Hand History for Game 11600365239 *****> Hint <$10 USD NL Texas Hold'em - Thursday, March 29, 20:33:40 EDT 2012> Hint <Table Speed #2439431 (No DP) (Real Money)> Hint <Seat 8 is the button> Hint <Total number of players : 9/9 > Hint <Seat 2: K.I.N.G. ( $9.80 USD )> Hint <Seat 3: Pyran1a ( $9.95 USD )> Hint <Seat 4: collocollo ( $21.46 USD )> Hint <Seat 7: fxm341 ( $10 USD )> Hint <Seat 8: gamas824 ( $11.07 USD )> Hint <Seat 9: george_shrub ( $9.70 USD )> Hint <Seat 5: gordonebula ( $10.45 USD )> Hint <Seat 1: kbzita88 ( $14.55 USD )> Hint <Seat 6: moliner0001 ( $10 USD )> debug1 <0.05 USD].> debug12
Manifest in this lovely piece of code
But the actually error occurs prior to this I think.
I know it is horrible code because I changed it for a different site
So there is a problem there even if it's not the one which cause the bug. I wrote this stuff ages ago and only recently revisited.Code:if (finished==FALSE){ //PROCESS SEATING do { rn=fscanf(game_file_ptr,"%[^\n]\n",var1); if (rn==-1) { printf("\n bad read1564b"); // END OF A GAME break; } if ((strncmp("-----",var1,5))==0) break; if ((strncmp("Seat ",var1,5))==0) { // printf("\n%s",var1); // sscanf(var1,"Seat %d: %s %[^\n]\n",&seatnum,player,var1); sscanf(var1,"Seat %d: %[^(] %[^\n]\n",&seatnum,player,var1); { int k; k=0; k=strlen(player) -1;player[k]=0;} printf("\nfinished loop <%s>", player); if(var1[0]!='\(') { // printf("\nZ2"); sscanf(var1,"%s",var2); if(strcmp(var2,"sits")){ /*printf("\nZ3");*/ sprintf(player,"%s %s",player,var2); } } printf("\nSEATED adding PLAYER <%s>",player); addlist(); seatfound=TRUE; onefound=TRUE; } else { seatfound = FALSE; } if ((onefound ==TRUE) && (seatfound ==FALSE)) { finished=TRUE; skipread=TRUE; /*printf("\nSKIPread\n");*/ break; } } while ( rn!=-1);/*not end of file or break at end of names */ if (rn==-1){ rn=0; break; } } /* if finished is false */ if (skipread==FALSE) { printf("\nHint <%s>",var1); rn=fscanf(game_file_ptr,"%[^\n]\n",var1); if (rn==-1) { printf("\n bad read1b4343"); // END OF A GAME break; } // printf("\nINPUT55<%s>",var1); skipread=TRUE; } skipread=FALSE;
One problem was using fscanf which skips over blank lines, that caused problems because the blank line indicates the end of a game, so instead I relied upon other things.
ie when someone wins the game as here.
Code:gamas824 does not show cards. gamas824 wins $0.15 USD Game #11600427288 starts. #Game No : 11600427288 ***** Hand History for Game 11600427288 ***** $10 USD NL Texas Hold'em - Thursday, March 29, 21:17:04 EDT 2012 Table Speed #2439431 (No DP) (Real Money)
However that caused problems when someone left the game as shown here, so things could get out of sync.
Code:fxm341 wins $1.50 USD kbzita88 has left the table. Game #11600428515 starts. #Game No : 11600428515 ***** Hand History for Game 11600428515 ***** $10 USD NL Texas Hold'em - Thursday, March 29, 21:18:01 EDT 2012 Table Speed #2439431 (No DP) (Real Money)
So I may have to rewrite that section. (which is gonna be a real pain as it involves sorting out the mess i made trying to cure it in the first place!!). I realise after I wrote it I could have done a number of things a lot better but I just want ed to get something up and working fast.
It's that long ago I can't remember myself what I was doing. Problem was when writing I didn't know all the things that could happen in a game
plus different sites have different approaches, some do one file per day someone file per table and some do one file per game.
And like when you read a line in you do not know what it will be, you do not know you have finished processing the players until
they start playing so you never know what to expect and it gets messy.
Your fscanf call is simply trying to pull a full line...instead use fgets, and a loop structure such as this:
Reason being, is fgets isn't going to "skip" the new line , it reads in everything up to a new line (or the size specified, so make sure you use buffer size big enough to fit a full line, or work in some logic to append to a buffer until you have a full line) so you can tell the end of the game the proper way-- by identifying the blank lines, something likeCode:... while (fgets(buf, SIZEOF_BUF, fp)) { if (ferror(fp)) { perror("read failed"); break; } ... }
if (!strcmp(buf, "\n")) may work if its a fairly clean line
Last edited by nonpuz; 01-10-2013 at 11:14 PM.
Okay...now that I actually look at the code you post, there are some serious memory issues here:
Code:/* OOPS! we're reading from and writing to the same variable: var1 */ sscanf(var1,"Seat %d: %[^(] %[^\n]\n",&seatnum,player,var1); { int k; k=0; k=strlen(player) -1;player[k]=0;} printf("\nfinished loop <%s>", player); if(var1[0]!='\(') { // printf("\nZ2"); /* we're now reading again from the corrupted var, to some other var that is never shown * how its declared.. */ sscanf(var1,"%s",var2); if(strcmp(var2,"sits")){
The size of the array is based on the number of player I expect to play so I make it a lot larger than it need be.
I print out the array at the end so I know if it is getting too big in which case I make the array bigger.
Not sure if I have a debugger.
The real underlying problem is more of a design error rather than a programming error, with perhaps a bit of confusion thrown in!!
The problem is because I don't always know what data is going to be thrown at the program,the design will sometimes be wrong.
Sometimes that is an an easy programming fix, other time more of a headache redesigning bits.
Often I am not aware if there is a problem unless it causes a crash because it means I would have to manually process hundreds of hands to check if the
program i correct!!
One way of knowing is to play at a table for a while and see if the program records the same profit/loss as indicated by my balance at the site.
Sometime events occur which are not recorded in the game file, for example you may be returned money bet which was not called.
It won't show as a win, some sites say it was returned some don't bother.
I am not actually sure if the program helps me play or not anyway, most of the time you never see the players again anyway!!
Last edited by esbo; 01-10-2013 at 11:31 PM.
This is the output from the program, however it seems I have perhaps introduced errors trying to fix it.
There should be a lot more data in there I think.
I am playing as george_shrub which is why I have more games
Code:(RealMoroni.txt 01 JAWAMAN1989 0.0X 0.00P 4G 0C 4G 0C 0.0W NaNX8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD JAWAMAN1989 Seat 02 vedder21 Sea 0.0X 0.00P 9G 0C 9G 0C 0.0W NaNX8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD vedder21 Seat 03 el ser Seat 0.0X 0.00P 36G 0C 9G 0C 0.0W NaNX8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD el ser Seat 04 george_shrub 0.0X 0.00P 1430G 0C 1336G 0C 0.0W 0.0X8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD george_shrub Seat 05 doloto_90 Se 0.0X 0.00P 5G 0C 5G 0C 0.0W NaNX8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD doloto_90 Seat 06 dinomerlin S 0.0X 0.00P 19G 0C 9G 0C 0.0W NaNX8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD dinomerlin Seat CoastalSuffolk.txt 01 AApoKerAA911 0.0X 0.00P 42G 0C 42G 0C 0.0W NaNX8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD AApoKerAA911 Seat 02 rybka4 Seat 0.0X 0.00P 67G 0C 65G 0C 0.0W NaNX8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD rybka4 Seat 03 george_shrub 0.0X 0.00P 1430G 0C 1336G 0C 0.0W 0.0X8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD george_shrub Seat 05 mrjimmy75 Se 0.0X 0.00P 14G 0C 14G 0C 0.0W NaNX8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD mrjimmy75 Seat 06 lie2me88 Sea 0.0X 0.00P 24G 0C 24G 0C 0.0W NaNX8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD lie2me88 Seat (RealPointe-Noire.txt 01 alanzan__ Se 0.0X 0.00P 35G 0C 32G 0C 0.0W NaNX8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD alanzan__ Seat 02 Mischgi69 Se 0.0X 0.00P 3G 0C 3G 0C 0.0W NaNX8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD Mischgi69 Seat 03 jabberwocky3 0.0X 0.00P 35G 0C 32G 0C 0.0W NaNX8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD jabberwocky31 Seat 04 amoreau007 S 0.0X 0.00P 58G 0C 55G 0C 0.0W 0.0X8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD amoreau007 Seat 05 Meroveus Sea 0.0X 0.00P 2G 0C 2G 0C 0.0W NaNX8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD Meroveus Seat 06 george_shrub 0.0X 0.00P 1430G 0C 1336G 0C 0.0W 0.0X8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD george_shrub Seat (RealSeoul.txt 01 grayslad Sea 0.0X 0.00P 63G 0C 63G 0C 0.0W 0.0X8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD grayslad Seat 02 Gizmo.electr 0.0X 0.00P 63G 0C 63G 0C 0.0W 0.0X8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD Gizmo.electric Seat 03 george_shrub 0.0X 0.00P 1430G 0C 1336G 0C 0.0W 0.0X8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD george_shrub Seat 04 camilloskate 0.0X 0.00P 57G 0C 57G 0C 0.0W 0.0X8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD camilloskate Seat 05 Myxarus Seat 0.0X 0.00P 63G 0C 63G 0C 0.0W 0.0X8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD Myxarus Seat 06 MistWar Seat 0.0X 0.00P 138G 0C 138G 0C 0.0W 0.0X8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD MistWar Seat 07 sereban_74 S 0.0X 0.00P 63G 0C 63G 0C 0.0W 0.0X8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD sereban_74 Seat 08 Kamovich Sea 0.0X 0.00P 51G 0C 51G 0C 0.0W 0.0X8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD Kamovich Seat (RealOrtaköy.txt 01 ignatio777 S 0.0X 0.00P 35G 0C 35G 0C 0.0W 0.0X8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD ignatio777 Seat 02 knobelclown 0.0X 0.00P 66G 0C 66G 0C 0.0W 0.0X8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD knobelclown Seat 03 hchch Seat 0.0X 0.00P 35G 0C 35G 0C 0.0W 0.0X8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD hchch Seat 04 Draganta333 0.0X 0.00P 59G 0C 59G 0C 0.0W 0.0X8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD Draganta333 Seat 05 kruteranio S 0.0X 0.00P 97G 0C 97G 0C 0.0W 0.0X8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD kruteranio Seat 06 Jr.Joe Seat 0.0X 0.00P 96G 0C 96G 0C 0.0W 0.0X8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD Jr.Joe Seat 07 MistWar Seat 0.0X 0.00P 138G 0C 138G 0C 0.0W 0.0X8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD MistWar Seat 08 george_shrub 0.0X 0.00P 1430G 0C 1336G 0C 0.0W 0.0X8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD george_shrub Seat 09 tjc1628 Seat 0.0X 0.00P 41G 0C 41G 0C 0.0W 0.0X8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD tjc1628 Seat (RealAtafu.txt 01 george_shrub 0.0X 0.00P 1430G 0C 1336G 0C 0.0W 0.0X8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD george_shrub Seat 02 bbk55 Seat 0.0X 0.00P 49G 0C 49G 0C 0.0W NaNX8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD bbk55 Seat 03 ladysonja90 0.0X 0.00P 49G 0C 49G 0C 0.0W NaNX8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD ladysonja90 Seat 04 Pinny1990 Se 0.0X 0.00P 10G 0C 10G 0C 0.0W NaNX8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD Pinny1990 Seat 06 Kriisol Seat 0.0X 0.00P 40G 0C 40G 0C 0.0W NaNX8 0%WON 0F 0%FW 0.0VIP 0%P 0%F 0%T 0%R NaN%SD Kriisol Seat Rake 0.000000
This is what a previous version of the output looked like, so you can see a lot of fields are missing. I think/hope that is due to some of the change I recently made.
Code:#1465022(Real.txt 06 Doppelhefe 7.1X 0.11P 14G 1C 14G 1C 2.0W 7.7X8 7.1CX3 14%WON 2F 14%FW 7%P 14%F 0%T 0%R NaN%SD Doppelhefe 03 Gin123555 21.0X 0.18P 138G 29C 138G 29C 15.5W 20.8X8 21.0CX3 11%WON 8F 6%FW 2%P 4%F 5%T 4%R 43%SD Gin123555 04 N_z4Ne 18.0X 0.52P 105G 20C 100G 18C 15.5W 19.2X8 19.0CX3 15%WON 10F 10%FW 16%P 12%F 4%T 3%R 40%SD N_z4Ne 01 Norbert1962 22.2X -0.29P 18G 4C 18G 4C 1.0W 7.7X8 22.2CX3 6%WON 1F 6%FW 0%P 0%F 0%T 6%R 0%SD Norbert1962 02 Predokk888 14.3X 9.53P 450G 66C 427G 61C 58.1W 14.0X8 14.7CX3 13%WON 40F 9%FW 12%P 6%F 2%T 1%R 62%SD Predokk888 07 Vincent19802 30.0X -0.84P 30G 9C 30G 9C 5.0W 33.3X8 30.0CX3 17%WON 4F 13%FW 0%P 3%F 13%T 3%R 33%SD Vincent19802 09 george_shrub 33.8X -88.77P 13101G 4290C 12219G 4127C 2109.4W 34.0X8 32.9CX3 16%WON 1416F 11%FW 5%P 14%F 7%T 5%R 40%SD george_shrub 08 supertom888 38.5X 0.30P 13G 5C 13G 5C 2.5W 38.5X8 38.5CX3 19%WON 1F 8%FW 8%P 23%F 0%T 0%R 50%SD supertom888 #1464750(Real.txt 03 Fless555 8.1X 0.03P 37G 3C 37G 3C 5.0W 8.1X8 8.1CX3 14%WON 4F 11%FW 11%P 0%F 0%T 0%R 100%SD Fless555 07 IQNUQ 9.0X 0.63P 211G 19C 211G 19C 18.5W 9.2X8 9.0CX3 9%WON 11F 5%FW 6%P 5%F 4%T 1%R 64%SD IQNUQ 01 M12shrooM 0.0X -0.02P 7G 0C 7G 0C 0.0W 0.0X8 0.0CX3 0%WON 0F 0%FW 0%P 0%F 0%T 0%R NaN%SD M12shrooM 09 Marcica71 16.9X -1.18P 160G 27C 160G 27C 8.5W 16.4X8 16.9CX3 5%WON 6F 4%FW 1%P 2%F 6%T 3%R 20%SD Marcica71 05 Mich278 9.3X 2.76P 182G 17C 182G 17C 13.5W 9.0X8 9.3CX3 7%WON 12F 7%FW 7%P 5%F 2%T 2%R 17%SD Mich278 06 george_shrub 33.8X -88.77P 13101G 4290C 12219G 4127C 2109.4W 34.0X8 32.9CX3 16%WON 1416F 11%FW 5%P 14%F 7%T 5%R 40%SD george_shrub 08 konstant1n99 18.3X 1.75P 93G 17C 93G 17C 14.5W 18.5X8 18.3CX3 16%WON 12F 13%FW 16%P 6%F 5%T 3%R 50%SD konstant1n99 02 vsischenko 14.9X -0.43P 47G 7C 47G 7C 6.5W 15.6X8 14.9CX3 14%WON 5F 11%FW 9%P 6%F 2%T 4%R 25%SD vsischenko 04 wih102 28.9X -1.60P 97G 28C 97G 28C 9.0W 28.1X8 28.9CX3 9%WON 6F 6%FW 0%P 4%F 2%T 2%R 27%SD wih102 Rake 0.000000 Rake 0.000000
Last edited by esbo; 01-10-2013 at 11:45 PM.
I am fortunate in that I do have a backup somewhere, I don't use any source code control as such so lucky I did some back up a few months ago.
But as you can see it did seem to be working with that error in at one point!!!!
You can also see I have not been having much luck
06 george_shrub 33.8X -88.77P
That means $88 dollars down!! The 33.8X is how many time I voluntarily take part in a game, note it is much higher than the others, one of the reasons I lose.
However those numbers may not be entirely accurate, for example if I miss off $0.01 per game I would be $131 down. But I think it might be about right.
16%WON 1416F 11%FW 5%P 14%F 7%T 5%R 40%SD george_shrub
Above we have the %age won, the number of 'forced wins' (players folded), the ammount I raised preflop P, post flop F, on the turn T and one the river R then the %age of showdowns won SD.
Sorry I can't post better figures!!
One thing worth bearing in mind is that even if you show a loss you do get free bonuses so a lot of it is not my money.
But it's very hard to win these days, I used to win in the past, £100 ever month for about 9 months.
Then something seemed to change and I could not win anymore!!!
Only recently started playing again I need to at least halve the amount of hands I play.