Black Jack

This is a discussion on Black Jack within the C Programming forums, part of the General Programming Boards category; I can't figure out why i get this error: In function ‚userinput‚: error: too few arguments to function ‚_IO_getc‚ Code: ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    41

    Black Jack

    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

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    getc() requires a FILE object. Instead, use getchar()

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making Black Jack
    By xeler8tor in forum C Programming
    Replies: 2
    Last Post: 12-14-2008, 03:13 AM
  2. can u fix this black jack code
    By onlinegeek in forum C++ Programming
    Replies: 2
    Last Post: 01-18-2006, 08:15 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. I need some ideas please>>
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 08-23-2002, 01:55 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21