Reputation: 667
I am having a issue where I want to return NULL if there are no "matches" in two strings versus '\0' if the string was empty to begin with. Is there a way to distinguish between the two?
In my case I have a function returning a char*. What are my options to have a distinction between the two so I can have two different print statements depending on if its NULL (meaning the character array wasn't null but returned null for conditional reasons in my logic) or '\0' (meaning the character array that was passed into the function was just the empty string "").
Thanks
Upvotes: 0
Views: 69
Reputation: 782166
if (ptr == NULL) {
// Stuff to do for NULL case
} elseif (*ptr == 0) {
// Stuff to do for empty string
} else {
// Stuff to do for other cases
}
Upvotes: 3