Thread: Check if array is empty?

  1. #1
    Registered User
    Join Date
    Nov 2021
    Posts
    11

    Check if array is empty?

    Code:
    struct pqueue {
            struct entry entries[10]; 
        }pqueue;
    
    
    How can i check if the entry array "entries" is empty?
    
    
    
        int isEmpty(struct pqueue* pqueue) (<- i have to use this function for this) {
    something like=
        if (pqueue.entries[10] = 0)
    ?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Easiest and simplest way is to just do
    Code:
    struct pqueue {
        int numEntries;
        struct entry entries[10]; 
    }pqueue;
    Then it's simply
    Code:
    int isEmpty(struct pqueue* pqueue) {
      return pqueue->numEntries == 0;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2021
    Posts
    11
    Quote Originally Posted by Salem View Post
    Easiest and simplest way is to just do
    Code:
    struct pqueue {
        int numEntries;
        struct entry entries[10]; 
    }pqueue;
    Then it's simply
    Code:
    int isEmpty(struct pqueue* pqueue) {
      return pqueue->numEntries == 0;
    }

    thank you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to check "struct tm" variable is empty?
    By krishnampkkm in forum C Programming
    Replies: 2
    Last Post: 01-11-2021, 10:50 PM
  2. Replies: 20
    Last Post: 07-07-2019, 08:48 AM
  3. Win API serial communication - how to check buffer is empty?
    By mr_monster in forum Windows Programming
    Replies: 3
    Last Post: 12-03-2012, 04:07 AM
  4. How to check if char* is empty or null??
    By earnshaw in forum C Programming
    Replies: 12
    Last Post: 12-15-2004, 07:13 AM
  5. How to check an empty int
    By johnnyd in forum C Programming
    Replies: 1
    Last Post: 03-31-2002, 08:42 AM

Tags for this Thread