I can't figure out why i get this error:
In function âuserinputâ:
error: too few arguments to function â_IO_getcâ
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define COMPUTER 0
#define HUMAN 1
#define NOBODY -1
#define WIN 1
#define DRAW 0
#define LOSE -1
#define OK 2
#define BLACKJACK 3
#define BUST 4
#define MAX_SIZE 52
#define TRUE 1
#define FALSE 0
int askmrpoker(int,int);
int cardvalue(int);
void init(void);
void swap(void);
void drawcard(int);
void takecard(int);
void userinput(void);
char *s[] = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
struct cd
{
int num;
int pat;
};
struct cd card[MAX_SIZE];
int who[MAX_SIZE];
int maxcard;
void takecard(int w)
{
who[maxcard]=w;
maxcard++;
}
void init()
{
int i;
maxcard = 0;
for(i=0; i<MAX_SIZE; i++)
{
card[i].num = i/4 ; /*0 to 12*/
card[i].pat = i%4 +3 ; /*3 to 6*/
who[i] = NOBODY;
}
}
void swap()
{
int i, j, k;
struct cd tmp;
for(i=0; i<MAX_SIZE; i++)
{
j = rand()%MAX_SIZE;
k = rand()%MAX_SIZE;
tmp = card[j];
card[j] = card[k];
card[k] = tmp;
}
}
void drawcard(int hide)
{
int i,hpos,cpos;
hpos = cpos =0;
for(i=0; i<maxcard; i++)
{
if(who[i] == HUMAN)
{
printf("%s\n",s[card[i].num]);
printf("%c\n",card[i].pat);
hpos++;
}
else
{
if(hide == TRUE)
{
printf("**\n");
printf("**\n");
}
else
{
printf("%s\n",s[card[i].num]);
printf("%c\n",card[i].pat);
}
cpos++;
}
}
printf("Computer Side\n");
printf("Human Side\n");
printf("Number of cards :%d\n",maxcard);
printf("Human Hand : %d\n",cardvalue(HUMAN));
printf("Computer Hand : %d\n",(hide==TRUE?0:cardvalue(COMPUTER)));
printf("H for Hit, S for stand, ESC for exit\n");
}
int cardvalue(int w)
{
int i,k,l,aflag,num;
k= num = aflag =0;
for(i=0; i<maxcard; i++)
{
if(who[i] == w)
{
k=card[i].num +1;
if(k>=2 && k<=10) /*2~10*/
num = num+k;
else
if(k>=10)
num = num+10;
else
aflag++;
}
}
for(l=0; l<aflag; l++)
{
if(num <= 10)
num = num+11;
else
num++;
}
return num;
}
int askmrpoker(int w, int o)
{
if( cardvalue(w) == 21)
return BLACKJACK;
if( cardvalue(w) >21 )
return BUST;
if( cardvalue(w) > cardvalue(o))
return WIN;
if( cardvalue(w) == cardvalue(o))
return DRAW;
if( cardvalue(w) < cardvalue(o))
return LOSE;
return OK;
}
void userinput()
{
int ch;
while(TRUE)
{
ch = (int)getc();
switch(ch)
{
case 27:/*ESC*/
break;
case 104:/*H for hit*/
takecard(HUMAN);
drawcard(TRUE);
break;
case 115:/*S for stand*/
return;
}
if(cardvalue(HUMAN) >= 21)
return;
}
}
main()
{
int i;
int start = TRUE;
srand(time(NULL));
rand();
do
{
if(start == TRUE)
{
init();
swap();
takecard(HUMAN);takecard(HUMAN);
takecard(COMPUTER);takecard(COMPUTER);
start = FALSE;
}
drawcard(TRUE);
userinput();
switch(askmrpoker(HUMAN, COMPUTER))
{
case BLACKJACK:
drawcard(FALSE);
start = TRUE;
printf("You Got BlackJack! \n");
system("pause");
break;
case BUST:
drawcard(FALSE);
start = TRUE;
printf("Loser ! \n");
system("pause");
break;
}
if(start == FALSE)
{
while( askmrpoker(COMPUTER,HUMAN) == LOSE )
{
takecard(COMPUTER);
drawcard(FALSE);
}
switch(askmrpoker(COMPUTER,HUMAN))
{
case BLACKJACK:
drawcard(FALSE);
start=TRUE;
printf("Pizza Cake! I got BlackJack! \n");
system("pause");
break;
case BUST:
drawcard(FALSE);
start=TRUE;
printf("@#$% I got bust! \n");
system("pause");
break;
case WIN:
drawcard(FALSE);
start=TRUE;
printf("Pizza Cake! I win \n");
system("pause");
break;
case DRAW:
drawcard(FALSE);
start=TRUE;
printf("A boring game. \n");
system("pause");
break;
case LOSE:
drawcard(FALSE);
start=TRUE;
printf("@#$% I lose! \n");
system("pause");
}
}
}
while(TRUE);
}
Any suggestions