In order to check if a dimension is empty you would need to check every element within the dimension. You can use a simple for loop to accomplish this.
There is, however, a problem with the code that you have posted. In you for loop you use sizeof(MessageQueue) which will not return QUEUE_LENGTH but rather QUEUE_LENGTH multiplied by BUFFER_LENGTH which will result in you accessing memory that you have not allocated.
This following code will do what you wish.
//Note that sizeof(MessageQueue) has been changed to QUEUE_LENGTH.
for(int i = 0; i < QUEUE_LENGTH; i++)
{
bool isEmpty = true;
for(int j = 0; j < BUFFER_LENGTH; j++)
{
if(MessageQueue[i][j] != 0)
{
isEmpty = false;
break;
};
};
if(isEmpty)
{
//DO SOME WORK.
//Exit the for-loop
break;
};
};
While the above code will check to see if a dimension is empty, it is unlikely that it will be if the array was just created. For this reason you will want to set every element of the array to 0 before doing anything with it. This can be done by placing the following for loop some where in you code that will be run before anything accesses the array.
for(int i = 0; i < QUEUE_LENGTH; i++)
{
for(int j = 0; j < BUFFER_LENGTH; j++)
{
MessageQueue[i][j] = 0;
};
};
I would suggest placing this for loop in a function such as void InitMessageQueue() and then simply calling that function in the initialization of the program.
QUEUE_LENGTH * BUFFER_LENGTHchars, andMessageQueue[i]will never be0declared as it is. Andsizeof(MessageQueue)is definitely not what you want to use for that loop top-end.MessageQueue[i][0]through toMessageQueue[i][BUFFER_LENGTH-1]are all 0.