Which is the most reliable way to check if a character array is empty?
char text[50];
if(strlen(text) == 0) {}
or
if(text[
The second one is fastest. Using strlen
will be close if the string is indeed empty, but strlen
will always iterate through every character of the string, so if it is not empty, it will do much more work than you need it to.
As James mentioned, the third option wipes the string out before checking, so the check will always succeed but it will be meaningless.