Since C-style strings are always terminated with the null character (\0), you can check whether the string is empty by writing

do {
   ...
} while (url[0] != '\0');

Alternatively, you could use the strcmp function, which is overkill but might be easier to read:

do {
   ...
} while (strcmp(url, ""));

Note that strcmp returns a nonzero value if the strings are different and 0 if they're the same, so this loop continues to loop until the string is empty.

Hope this helps!

Answer from templatetypedef on Stack Overflow
🌐
Cprogramming
cboard.cprogramming.com › c-programming › 117372-check-if-string-null.html
Check if string is null
Can you tell me how to check if a string is null in C? I tried p != '\0' doent seem to wrk though! It all depends on what you mean, and what p is declared as. That looks like an empty string check to me.
🌐
C For Dummies
c-for-dummies.com › blog
Null Versus Empty Strings | C For Dummies Blog
You must compare the two: Create an empty string or null string as a sample, then use the strcmp() function to compare them. A null string compares to another null string, and an empty string to an empty one. #include <stdio.h> #include <string.h> int main() { char empty[5] = { '\0' }; char ...
🌐
Reddit
reddit.com › r/learnprogramming › how do i compare a string to null in c++?
r/learnprogramming on Reddit: How do I compare a string to NULL in C++?
September 27, 2019 -

I need to simply check if an object in a string vector is null or not:

std::vector<string> vliwSlots;
//Some inserts...
string vliwSlot = vliwSlots.at(i); //in a for loop
if(vliwSlot != NULL){ //error on this line
    //Do stuff
}

When I compile this I get the following error at :

no match for ‘operator!=’ (operand types are ‘std::__cxx11::string {aka std::__cxx11::basic_string<char>}’ and ‘long int’)

It seems it thinks NULL is a long int. How the heck do I check if a string is null?

🌐
Sabe
sabe.io › blog › c-check-string-empty
How to Check if a String is Empty in C
March 19, 2022 - Therefore, if the length of the string is 0, then the first character of the string is a null character. ... CLIKE#include <stdio.h> #include <string.h> int main() { char string[] = ""; if (string[0] == '\0') { printf("String is empty"); } else ...
🌐
Quora
quora.com › How-do-I-check-if-a-string-is-empty-in-C
How to check if a string is empty in C - Quora
Answer (1 of 10): Many of the answers I have seen here are well-intentioned, but also use outdated methods. Assuming that all strings are ANSI formatted is an incomplete answer. Well, first of all, C does not have a string type. A string in C is essentially a set of characters in contiguous mem...
🌐
GameDev.net
gamedev.net › forums › topic › 421554-c-how-do-i-check-if-a-stdstring-is-null › 3807807
[C++] How do I check if a std::string is NULL? - General and Gameplay Programming - GameDev.net
October 30, 2006 - However, it seems that std::string has an overriden operator == which doesn't allow me to check if it is null. (If could try void setName(std::string* newName), but thet setName("name") wouldn't work). Any advice would be appreciated! ... if (newName.empty()) this->name = "Default"; That will work of you call setName(""), you can't call setName(NULL), unless you used a pointer as an argument, but what you really should use is a constant reference instead of passing by value.
🌐
Cplusplus
cplusplus.com › reference › string › string › empty
std::string::empty
Returns whether the string is empty (i.e. whether its length is 0). This function does not modify the value of the string in any way. To clear the content of a string, see string::clear.
Find elsewhere
🌐
tutorialpedia
tutorialpedia.org › blog › how-to-check-if-c-string-is-empty
How to Check if a C String is Empty: Practical Example for User Input Loop Termination — tutorialpedia.org
By defining "empty" as a string with only the null terminator ('\0'), we can use simple methods like checking the first character (str[0] == '\0'), strlen(str) == 0, or strcmp(str, "") == 0.
🌐
Quora
quora.com › How-do-you-check-for-an-empty-string-and-null-character-in-the-C-programming-language
How to check for an empty string and null character in the C# programming language - Quora
Answer: You first have to explain what “ermpty” means for you. However, i always use [code ]String.IsNullOrEmpty[/code] if i want to know if the string is either null or an empty string(“”), so contains no letters, not even white-spaces. You also can use [code ]String.IsNullOrWhiteSpac[/code]`. T...
🌐
Educative
educative.io › answers › how-to-check-if-a-string-is-null-or-empty-in-c-sharp
How to check if a string is null or empty in C#
IsNullOrEmpty() returns true if the input is an empty string. In C#, this is a zero length string (""). ... string str1 = ""; string str2 = String.Empty; Console.WriteLine(String.IsNullOrEmpty(str1)); // True Console.WriteLine(String.IsNull...
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › check-if-string-is-empty-in-cpp
How to Check if a String is Empty in C++? - GeeksforGeeks
July 23, 2025 - To check for an empty string we can use the std::string::empty() function because what the empty function does is it checks for the length of a string and if the string is empty, it returns true, otherwise, it returns false.
🌐
Quora
quora.com › How-can-I-check-for-input-string-validity-Check-if-the-input-string-is-null-if-it-is-return-null-in-C-language
How can I check for input string validity? Check if the input string is null; if it is, return null in C language.
Answer (1 of 4): [code]const char* is_something(const char* str) { if(!str || !*str) return NULL; return str; } [/code]A string in C is a null -terminate sequence of character. A null string is a string containing just a terminator. And since string are passed around as pointer to the sequence...
🌐
UiPath Community
forum.uipath.com › help
How to check if a string is not empty? - Help - UiPath Community Forum
March 3, 2020 - Hi all, I’m reading a text from certain position and entering into a do while loop to work on some actions. The text will contain different strings each time and to perfom these activies inside the do while loop the te…
🌐
Medium
medium.com › @deepakha1993 › c-string-null-empty-and-white-space-check-8d5409c04f6c
C# - String Null, Empty and White space check | by Deepak H A | Medium
September 21, 2024 - The value of a string variable can be either null or empty or can contain white spaces. Frequent checks need to be carried out on any string variable against these possibilities. To perform these checks, dot net framework class library provides two extension methods for string. ... To clearly understand, let’s run the below code: (Create a console application in your preferred IDE. I used Visual Studio 2022) string name = ""; if (string.IsNullOrEmpty(name)) { Console.WriteLine("Name is empty"); } if (string.IsNullOrWhiteSpace(name)) { Console.WriteLine("Name has whitespaces"); }