Best way to check if a character array is empty

Viewed 255718

Which is the most reliable way to check if a character array is empty?

char text[50];

if(strlen(text) == 0) {}

or

if(text[0] == '\0') {}

or do i need to do

 memset(text, 0, sizeof(text));
 if(strlen(text) == 0) {}

Whats the most efficient way to go about this?

7 Answers
if (!*text) {}  

The above dereferences the pointer 'text' and checks to see if it's zero. alternatively:

if (*text == 0) {} 
Related