StyleZ
StyleZ

Reputation: 1273

How to check if there is something stored in an array element or not

I would like to make a condition, to see, if there is something than an empty array

char data[12][100];
int i;
int sum = 12;
for (i = 0; i <= sum; i++)
{
   printf("Hello \n");
   printf("%d \n", sizeof(data[sum][0]));
   if(data[sum][0] != NULL){
      return 0;
   // code fillin data[][] + some printfs
}

I have tried this code ... but it gets stuck in that condition (sizeof is telling me, that its = 1, but I feel like that's the size of that 1 specific element ) so any idea, how can I check if its empty or not ?

also, here is output I get:

Hello 
1 

expected :

Hello 
1 
// Some other printfs

Upvotes: 0

Views: 508

Answers (1)

Amine
Amine

Reputation: 941

Arrays always contain values so you have to know the value/values you want present in your array in order to work with which in this situation count as the "empty" values that you're talking about.

Upvotes: 1

Related Questions