How can I check if char* variable points to an empty string?
How can I check if char* variable points to an empty string?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Check if the first character is ‘\0’. You should also probably check if your pointer is NULL.
You could put both of those checks in a function to make it convenient and easy to reuse.
Edit:
In the if statement can be read like this, “If c is not zero and the first character of character array ‘c’ is not ‘\0’ or zero, then…”.
The
&&simply combines the two conditions. It is basically like saying this:You may want to get a good C programming book if that is not clear to you. I could recommend a book called “The C Programming Language”.
The shortest version equivalent to the above would be: