Link to home
Start Free TrialLog in
Avatar of someotherdude
someotherdude

asked on

New to C programming; don't understand error msg

Hi, I'm new to C programming.  I've read some tutorials online to get the fundamentals and decided to start out by programming a simple BlackJack program.  I use CodeWarrior to compile it and then I run down the list of errors and try to fix them one by one.  So far I've got it down to only 88 errors : )  But now I'm stuck on one that I can't figure out.  

When I define the function userdraw(), which allows the player to draw from a 52 card deck


int userdraw(int usercards[5], int *unumber, int p)
{
      int ucard = 0;
      *unumber = &usercards[p]
      getcard(ucard);     //<-------this is where the error shows
      *unumber = ucard;
      unumber++;
      p++;
}


I get the message:

--------------------------------------------------------
Error : cannot convert
'int *' to
'int'
Blackjack.c line 30   getcard(ucard);
--------------------------------------------------------

What does this mean?  I know the * symbol has to do with arrays and pointers but have no idea what it means here.  Any solution/suggestion you guys can offer will be greatly appreciated

If you need more info, here is all of the program that I have writen so far, and yes, I know, it's full of errors.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
time_t time(time_t *timer);

int r;

int getcard(int card) /* gets a random number from 1 to 52 */
{
      /* int i; */
      unsigned int seed;
            

      for (seed = 1; seed <= 5; seed++) {
            srand(seed);
            }
      
      card = rand()%51+1;
      return card;
            
}
      
int userdraw(int usercards[5], int *unumber, int p)
{
      int ucard = 0;
      *unumber = &usercards[p]
      getcard(ucard);     //<-------this is where the error shows
      *unumber = ucard;
      unumber++;
      p++;
}

int dealerdraw(int dealercards[5], int *dnumber, int q)
{
      int card = 0;
      getcard(card);
      dealercards[dnumber] = card;
      dnumber++;
      q++;
}

int cardsort(int hand[5], int redraw, int total)
{
      int numvalue;
      int cnumber = 0;
      
      while(cnumber < 4)
      {
            int i = cnumber + 1;
            while (i < 4)
            {
                  if (hand[cnumber] == hand[i])
                  redraw = 1;
                  return redraw;
            }
            i = 0;
            cnumber = 0;
            
            numvalue = 13 - hand[cnumber] % 13;
            
            if (numvalue > 10)
                  numvalue = 10;
            
            total += numvalue;
            
            if (cnumber > 2 && hand[cnumber] == 1 && total < 21)
                  {
                  hand[cnumber] = 11;
                  total += 10;
                  }
                  
            if (cnumber > 2 && hand[cnumber] == 11 && total > 21)
                  {
                  hand[cnumber] = 1;
                  total -= 10;
                  }
                                     
            cnumber++;
      }
      
      
}

int firstdeal()
{
      
      int dealercards[5];
      int usercards[5];
      int i = 0;
      int p = 0
      int q = 0
      int *unumber = &usercards[0];
      int *dnumber = &dealercards[0];
      int usertotal = 0;
      int dealertotal = 0;
      int redraw;
      while (i < 5)
      {
            dealercards[i] = 0;
            usercards[i] = 0;
            i++;
      }      
      i = 0;
      
      dealerdraw(dealercards[], *dnumber, q);
      dealerdraw(dealercards[], *dnumber, q);
            
      cardsort(dealercards, redraw, dealertotal);
      
      while redraw      
      {
            dnumber--;
            dealerdraw();
            cardsort(dealercards, redraw, dealertotal);
            
      }
      
      userdraw();
      userdraw();
      
      cardsort(usercards, redraw, usertotal);
      
      while redraw
      {
            unumber--;
            userdraw();
            cardsort(usercards, redraw, usertotal);
      }      
      displaytable()
      
}

int displaytable()
{
      int i = 0;
      char dschar[5];
      char dfchar[5];
      char uschar[5];
      char ufchar[5];
      
      for (i = 0; i < 5; i++)
      {
            dschar[i] = dealercards[i] / 13 + 167;
            uschar[i] = usercards[i] / 13 + 167;
            
            if dealercards[i] == 11
                  dfchar[i] = 'J';
            if dealercards[i] == 12
                  dfchar[i] = 'Q';
            if dealercards[i] == 13
                  dfchar[i] = 'K';
            if dealercards[i] == 1
                  dfchar[i] = 'A';            
            if dealercards[i] == 10
                  dfchar[i] = 'T';      

            if usercards[i] == 11
                  ufchar[i] = 'J';
            if usercards[i] == 12
                  ufchar[i] = 'Q';
            if usercards[i] == 13
                  ufchar[i] = 'K';
            if usercards[i] == 1
                  ufchar[i] = 'A';
            if usercards[i] == 10
                  ufchar[i] = 'T';
            
            if usercards[i] < 9
                  ufchar[i] = usercards[i] + 47                  
            
            if dealercards[i] < 0
                  dfchar[i] = dealercards[i] + 47
                  
            if usercards[i] == 0
            {
                  ufchar[i] = 'x';
                  uschar[i] = 'x';      
            }
            
            
            
      }
      

      printf("----BlackJack v1.0 by John Saville---- \n \n \n");
      printf("-------     -------     -------     -------     ------- \n");
      printf("-%c   %c-     -%c   %c-     -%c   %c-     -%c   %c-     -%c   %c- \n" , uschar[0], ufchar[0], uschar[1], ufchar[1], uschar[2], ufchar[2], uschar[3], ufchar[3], uschar[4], ufchar[4]);
      printf("-     -     -     -     -     -     -     -     -     - \n");
      printf("- %c -     - %c -     - %c -     - %c -     - %c - \n" , ufchar[0], ufchar[1], ufchar[2], ufchar[3], ufchar[4]);
      printf("-     -     -     -     -     -     -     -     -     - \n");
      printf("-%c   %c-     -%c   %c-     -%c   %c-     -%c   %c-     -%c   %c- \n" , uschar[0], ufchar[0], uschar[1], ufchar[1], uschar[2], ufchar[2], uschar[3], ufchar[3], uschar[4], ufchar[4]);
      printf("-------     -------     -------     -------     ------- \n");
      
      printf("\n \n \n \n")
      
      printf("-------     -------     -------     -------     ------- \n");
      printf("-%c   %c-     -%c   %c-     -%c   %c-     -%c   %c-     -%c   %c- \n" , dschar[0], dfchar[0], dschar[1], dfchar[1], dschar[2], dfchar[2], dschar[3], dfchar[3], dschar[4], dfchar[4]);
      printf("-     -     -     -     -     -     -     -     -     - \n");
      printf("- %c -     - %c -     - %c -     - %c -     - %c - \n" , dfchar[0], dfchar[1], dfchar[2], dfchar[3], dfchar[4]);
      printf("-     -     -     -     -     -     -     -     -     - \n");
      printf("-%c   %c-     -%c   %c-     -%c   %c-     -%c   %c-     -%c   %c- \n" , dschar[0], dfchar[0], dschar[1], dfchar[1], dschar[2], dfchar[2], dschar[3], dfchar[3], dschar[4], dfchar[4]);
      printf("-------     -------     -------     -------     ------- \n");
      
      
}

main() {
      printf("BlackJack by John Saville \n");
      printf("\n \n \n");
      firstdeal();
      return 0;
}
ASKER CERTIFIED SOLUTION
Avatar of migoEX
migoEX

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kalyanreddy_kk
kalyanreddy_kk

The statement "*unumber = ucard;" is not correct, since when ucard is specifying an address and u r trying to store it in an interger variable "*unumber"

Remember, when u say, *variablename, u r referring to the location where the value is stored, and not the location where the address is stored.
Hi,

If you put a semi-colon at the end of line 29, then you should see that the error is actually on line 29 and not on line 30.
I dont understand why you are trying to assign a value to unumber in line 29, when its not even used before its assigned a new value a few rows down.
Maybe you could just get rid of that line?

More specific to your question:

I think you might also be a little confused at the use of the inderication operator (*).  This operator allows you to reference the data that a pointer points to.  So on line 29, currently you are saying that the value of unmber (which should be an integer) should be assigned with a pointer to an integer - that clearly is not possible, which is why the compiler is saying that it cannot covert a pointer to an intger to an actual integer.  I think what you mean to do there is make unmber point to the same as whats on the right hand side, you can do this by removing the * at line 29.

That should sort out your problem, but it does make me wonder that you might have made similar mistakes in the same place which might not be caught by the compiler, thus giving you unexpected results.

Let me know how it goes!
Whats the latest someotherdude??
Avatar of someotherdude

ASKER

I decided to scrap what I had and start anew.  I'm still working on the new one and so far have gotten rid of the syntax errors.  I'm hoping to have it finished by next week.  Anyway, here it is.  Remember this is my first C program and it is unfinished.


// A minimal Win32 console app

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
time_t time(time_t *timer);


int getcards(int cardsavail[]) /* gets ten random numbers ranging from 2 to 52.  These will       

                  be all the cards available to both the user and the dealer.             

            */
{

      
      int i;
      int j;
      int k;
      
            
      for (i = 0; i < 10; i++)
      {
            
      
            srand(time(NULL) + i);
            cardsavail[i] = rand()%52+1;
            
            
            for (j = 0; j < i; j++)  // decrements loop if two cards match
            {
                  
                  for (k = j + 1; k < i; k++)
                  {
                        if (cardsavail[k] == cardsavail[j])
                              i--;
                  }            
            }      
      }      
      
      
            
}


int drawcard(int hand[], int playerplace, int place, int cardsavail[])
//draws a card
{

      
      hand[playerplace] = cardsavail[place];
      place = place + 1;
      playerplace = playerplace + 1;
      return playerplace;
      return place;
}      


      
      
int tabledisplay(int dealercards[], int usercards[], int userplace, int dealerplace, int

pot, int cardsavail[], char suitvalue[])
//provides output to user
{
      int even = 0;
      int odd = 0;
      int item = 0;
      int printc = 0;
      char prints = 0;
      printf("\n BlackJack by John Saville \n");
      printf("\n \n \n \n");

      printf("Dealer's Hand \n \n");
      for (item = 0; item < dealerplace; item++)
      {

            if (item == 0)
            printf("%c",'X'); // first dealer card
            if (dealercards[item] == 13){
            printf("%c",'A');
            dealercards[item] = 11;
            }if (dealercards[item] == 10){
            printf("%c",'J');
            dealercards[item] = 10;
            }if (dealercards[item] == 11){
            printf("%c",'Q');
            dealercards[item] = 10;
            }if (dealercards[item] == 12){
            printf("%c",'K');
            dealercards[item] = 10;
            }if (dealercards[item] < 11){
            printf("%d",dealercards[item]);
            even = item * 2;}
            
            if (item == 0)
            printf("%c",' ');// is hidden
            if (item != 0)
            printf("%c ",suitvalue[even]);
            
      }      
      item = 0;
      printf("\n \n \n \n");
      printf("Your Hand \n \n");
      for (item = 0; item < userplace; item++)
      
      {
            if (usercards[item] == 13){
            printf("%c",'A');
            usercards[item] = 11;
            }if (usercards[item] == 10){
            printf("%c",'J');
            usercards[item] = 10;
            }if (usercards[item] == 11){
            printf("%c",'Q');
            usercards[item] = 10;
            }if (usercards[item] == 12){
            printf("4c",'K');
            usercards[item] = 10;
            }if (usercards[item] < 11){
            printf("%d",usercards[item]);
            odd = (item + 1) * 2 - 1;}
            printf("%c ",suitvalue[odd]);
            
      }      
      printf("\n \n \n \n");
      
      
      printf("\n \n \n \n");
      printf("Pot %d  $ \n", pot);
      
}

cardsort(int cardsavail[], char suitvalue[])
//determines the suit and value of each card
{
      int count = 0;
      
      for (count = 0; count < 10; count++)
      {
            suitvalue[count] = cardsavail[count] / 13 + 3;      
      
      }      

      count = 0;      

      for (count = 0; count < 10; count++)
      {
            cardsavail[count] = cardsavail[count] % 14;
      }

}


main()
{

      

      int pot = 1000;
      int cardsavail[10] = {0,0,0,0,0,0,0,0,0,0};
      char suitvalue[10] = {0,0,0,0,0,0,0,0,0,0};
      int usercards[5] = {0,0,0,0,0};
      int dealercards[5] = {0,0,0,0,0};
      int place = 0;
      int userplace = 0;
      int dealerplace = 0;
      int count = 0;
      int wager = 0;
      int totalwager = 0;
      int usertotal = 0;
      int dealertotal = 0;
      char play = 's';
      char again = 'y';

      while (again == 'y')
      {
      getcards(cardsavail);
      cardsort(cardsavail, suitvalue);
      for (count = 0; count < 2; count++)
      {
            drawcard(dealercards, dealerplace, place, cardsavail);
            place++;
            dealerplace++;
            drawcard(usercards, userplace, place, cardsavail);
            place++;
            userplace++;
      }
      
      count = 0;
      for (count = 0; count < 5; count++);
      {
            usertotal = usertotal + usercards[count];
            dealertotal = dealertotal + dealercards[count];
      }      
            
      tabledisplay(dealercards, usercards, userplace, dealerplace, pot, cardsavail,             

      suitvalue);

      printf("Enter the amount you wish to wager followed by ENTER followed by an h for

hit or an s for      stand followed by ENTER \n");
      scanf("%d %c", &wager, &play);      
      printf("you wagered %d $ and choose %c", wager, play);
            
      totalwager = totalwager + wager;
      pot = pot - totalwager;
      
      
            
      if (play == 'h');{      
      drawcard(usercards, userplace, place, cardsavail);
      place++;
      userplace++;
      usertotal = usertotal + usercards[userplace];}
      

      if (usertotal > 21);{
      count = 0;
      for (count = 0; count < userplace; count++)
      {
            if (usercards[userplace] = 11)
            usercards[userplace] = 1;
      }
      if (usertotal > 21);{
      tabledisplay(dealercards, usercards, userplace, dealerplace, pot, cardsavail,             

      suitvalue);             
      printf("you bust, dealer wins \n");
      totalwager = 0;
      printf("Again y/n");
      scanf("%c", &again);}}
      
      

      

      if (play == 's');{      
      
      while (dealertotal < 15);
      {
            count = 0;
            for (count = 0; count < dealerplace; count++)
            {
                  if (dealercards[count] = 11){
                  if (dealertotal > 21){
                  dealercards[count] = 1;}}
                  
            }
            drawcard(dealercards, dealerplace, place, cardsavail);
      }
            
      if (dealertotal > 21){
      printf("dealer bust, you win \n");
      pot = pot + (totalwager * 2);
      printf("Again y/n");
      scanf("%c", &again);}}
      


      }


      return 0;
}
Hummm... I think all the experts picked up some of the problems, and normally a split all experts would be the way to go.. but its only 50 points.  So would say it was answered by migoEX and possibly split with dennis_george