c - What is the difference between char *str being null and str[0] == '\0' -
i have pointer char *str;
for particular case, if (!str) not null str[0] == '\0', how , when possible?
edit:0 responses. need pass string source param in strlcpy() sag faulting because empty string. seems need check this: if (!str || str[0] == '\0') not pass strlcpy(). sound right?
\0 null-byte or null-terminator. therefore, seen null. c-strings null-terminated. is, first time null-byte seen, string considered complete. if nothing other \0 exists, null.
if have information beyond byte (this bad practice strings) try check str+1 advance passed null-byte. in event, str+1 , on garbage data , cause invalid memory accesses (causing program crash).
Comments
Post a Comment