Hi,
Can you tell me how to check if a string is null in C?
I tried p != '\0' doent seem to wrk though!
thanks
Hi,
Can you tell me how to check if a string is null in C?
I tried p != '\0' doent seem to wrk though!
thanks
Do you want to test if a character array points to NULL or a string is empty? Your wording doesn't make much sense.
But the two I said:
Code:p == NULL /* True if character array points to NULL */ !*p or *p == '\0' /* True if string empty */
keep in mind that if i didn't write the assignment (p=NULL) its value would be undefined and the if statement wouldn't work. in a string '\0' is the terminating null byte, you can check when a string is finished but you need to dereference the address:Code:char *p=NULL; if (!p) printf("p is null"); else printf("p is not null");
Hope that helpedCode:char *p; if (*p=='\0')...
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"