Merge pull request #106 from xexyl/1990-cmills

Make 1990/cmills use fgets() instead of gets()
This commit is contained in:
Landon Curt Noll authored and GitHub committed 2023-03-21 15:41:58 -07:00
commit 32f2f1b29c
2 files changed
+20 -10

No files matched your search

+18 -8
View File
@@ -18,27 +18,37 @@ We used a patch from [Yusuke Endoh](/winners.html#Yusuke_Endoh) to get this to
work in modern systems (it resulted in a bus error otherwise). Thank you Yusuke
for your assistance!
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) made the program safer
by using `fgets()` instead of `gets()`. Thank you Cody for your help in making
this safer! For the original code you can change the instances of:
!fgets(l,M,stdin)
to:
!gets(l)
### Try:
./cmills 5000
NOTE: this program uses `gets()` so you will likely get a warning under modern
systems.
## Judges' comments:
## Judges' comments
Compile notes:
cc -DM=500 -DN=52 -DX="srand((int)time(0L))" -DV=void -o cmills cmills.c
The Makefile uses several `-D` defines. The following is is a list of the macros
that may be changed:
-DM=<max bet allowed>
-DN=<52 * number of decks used>
-DX=<how to seed the rand() generator>
-DV=<void ot int>
## Author's comments
The macro `V` should remain `void`.
## Author's comments:
This is a blackjack program. It does splits, doubling down,
insurance, etc.
+2 -2
View File
@@ -7,13 +7,13 @@
#define B(n)b(l,n),(V)printf(l
V
exit();char*g,c[M],d[N],q[N],p[N],*e,*r=d+N,l[M],t[]="??",*k,*m="DEATHISDSev2oinpohae3ttsluuln4a?uibfe 5l\0rtlfrb6 ?a?el:e7$!n\0?e t8%ccp\0.%s9deelc.s T.@?-t.\t<J /\0=a\nP=Q Sex \0l KW Sin a$\0ane-lay% ge#-slediefuk ar r$via-:o ?+}:r? n \0:) ee%lone 1-esy666!-~v\n.!^`'~@#\0\np~===:=q";b(o,n)char*o;{for(k=n+m;*o++=*k;k+=9);}int
y=M*2,v,x,s,f,j,o;u(s){B(s));if(!gets(l))exit(0);return(o=
y=M*2,v,x,s,f,j,o;u(s){B(s));if(!fgets(l,M,stdin))exit(0);return(o=
*l)=='y'||o=='Y'||o!='n'&&o!='N'&&u(s);}h(v,m){for(k=c;*k!='J';)if(m==*k++)break;m=k-c;if(v<0)W(v=m-v)
if(m==1)W(v+=11)
v+=m;return
v;}main(w,z)char**z;{b(c,2)*X;for(--w&&(y=atoi(1[z]));y>1;){if(r-d>N*3/4){B(8));F++r)*r=c[(r-d)%13];F)w=
*(g=d+rand()%N),*g=
*r,*r++=w;r=d;}for(;;){B(3),y);if(!gets(l)||(w=atoi(l))<1)exit(0);if(w&1||w>M||w>y)B(1),y<M?y:M);else
*r,*r++=w;r=d;}for(;;){B(3),y);if(!fgets(l,M,stdin)||(w=atoi(l))<1)exit(0);if(w&1||w>M||w>y)B(1),y<M?y:M);else
break;}y-=w,s=f=j=x=v=0,g=q,e=p;H(x,g)H(x,g)H(v,e)H(v,e)*t=
*q;S(t)*q=='A'&&y>=w/2&&u(5)&&(y+=(3*(h(0,1[q])==10)-1)*w/2);if(x==-21)goto
_;if(v==-21){y+=w/2;goto