Thread: Empty Integer Array

  1. #1
    Registered User
    Join Date
    Feb 2016
    Posts
    27

    Empty Integer Array

    I'm trying to check an integer array if it's empty. I stored ROGUE values in the array where should be empty and I'm not getting to check if my array is empty or not. Someone please help

    Code:
    /*Checks if a player's hand is empty.
    The first player to have an empty hand wins the game so this function is necessary.*/
    int isEmpty(CardPtr Hand){
        int i=0; //counter
        while (i<NCARDS){
            if (Hand[i].face == ROGUE && Hand[i].suit == ROGUE){
                i++;
            }
            else printf("Not empty\n");
        }
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Sep 2014
    Posts
    364
    Your function return a integer that say if the hand has cards or not.
    Have the player cards, the function should return 0.
    If the hand is empty, the function should return 1.

    This means, if you find a valid card in the loop, you can stop and return 0.
    If the loop runs up to NCARDS, there is no valid card.
    Code:
    /*  Checks if a player's hand is empty.
        The first player to have an empty hand wins the game so this function is necessary.
        Return: 1 if hand is empty, 0 otherwise
    */
    int isEmpty(CardPtr Hand) {
        int i;
        for (i = 0 ; i < NCARDS ; i++) {
            if (Hand[i].face != ROGUE || Hand[i].suit != ROGUE) return 0;
        }
        return 1;
    }
    Last edited by WoodSTokk; 05-05-2016 at 06:25 PM.
    Other have classes, we are class

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Empty Array
    By edmund085 in forum C Programming
    Replies: 5
    Last Post: 09-03-2011, 04:50 PM
  2. Empty Array?
    By Terran in forum C++ Programming
    Replies: 2
    Last Post: 06-16-2008, 12:47 AM
  3. Empty an Array
    By Charlin in forum C++ Programming
    Replies: 11
    Last Post: 01-12-2008, 02:48 PM
  4. Is there a code that means a integer is empty?
    By Roy01 in forum C++ Programming
    Replies: 13
    Last Post: 10-22-2006, 04:06 AM
  5. Empty Array
    By devilsknight in forum C Programming
    Replies: 16
    Last Post: 07-18-2006, 09:52 PM

Tags for this Thread