Best way to check if a character array is empty

后端 未结 7 2015
臣服心动
臣服心动 2020-12-13 02:15

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

char text[50];

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

or

if(text[         


        
7条回答
  •  感情败类
    2020-12-13 02:38

    This will work to find if a character array is empty. It probably is also the fastest.

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

    This will also be fast if the text array is empty. If it contains characters it needs to count all the characters in it first.

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

提交回复
热议问题