I have a pointer char *str;
for a particular case, if (!str) is not NULL but str[0] == '\0', how and when is this possible?
Edit:0
Thanks for all the responses. Basically I need to pass this string as a source param in strlcpy() which is sag faulting because this is an empty string. It seems I need a check something like this: if (!str || str[0] == '\0') than do not pass to strlcpy(). Does that sound right?
\0is the null-byte or null-terminator. Therefore, it is seen as null. C-strings are null-terminated. That is, the first time a null-byte is seen, the string is considered complete. If nothing other than\0exists, it isNULL.If you have information beyond this byte (this is bad practice for strings) you could try to check
str+1which will advance passed the null-byte. In any event,str+1and so on could very well be garbage data and cause invalid memory accesses (causing your program to crash).