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
🌐
C For Dummies
c-for-dummies.com › blog
Null Versus Empty Strings | C For Dummies Blog
August 12, 2017 - An empty string has a single element, the null character, '\0'. That’s still a character, and the string has a length of zero, but it’s not the same as a null string, which has no characters at all. ... The name array is null string. That doesn’t mean that it has a null character ('\0') ...
Discussions

What is the best way to check for a blank string?
To check if a string is blank in JavaScript all you wound need is this: if (foo){ //do stuff... } The if condition will evaluate "true" is foo is not null, undefined, NaN, empty string, 0, or false. http://stackoverflow.com/questions/5515310/is-there-a-standard-function-to-check-for-null-undefined-or-blank-variables-in More on reddit.com
🌐 r/learnprogramming
5
2
December 2, 2015
How to get the address of string ""
🌐 forum.nim-lang.org
string variable unexpectedly becomes an empty string
Both of your scanf calls, as well as your final printf call, are invalid. When reading the name you should use: scanf("%s", name); name will decay to a pointer to its first element. That's a pointer to a char. The %s specifier requires a pointer to a char. The types match — good! When reading the age you should use: scanf("%hu", &age); &age is a pointer to an unsigned short. The %hu specifier requires a pointer to an unsigned short. The types match — good! When printing the age you should use: printf("You are %hu years old\n", age); age is an unsigned short. The %hu specifier requires an unsigned short. The types match — good! It's very important that the types expected by your format specifiers match the types of the arguments you actually pass. If they don't match, the code is invalid. (There are certain cases when you get away with the "wrong" specifier in printf, but it's always best to use the correct one. And scanf isn't so lenient — the types must match there.) More on reddit.com
🌐 r/cprogramming
10
0
February 27, 2024
Should we optimize or deprecate `string.Empty` in C#?
There are 2 representation for an empty string in C#, "" and string.Empty. Both finally refer to the same single string instance after compiled by JIT, but string.Empty is less optimized ... More on github.com
🌐 github.com
1
1
April 20, 2024
🌐
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...
🌐
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.
🌐
MathWorks
la.mathworks.com › polyspace bug finder › review analysis results › complete list of polyspace bug finder results › defects › performance defects
Expensive use of string functions from the C standard library - String functions from the C standard library are used inefficiently - MATLAB
Correction — Check for Empty C-String by Comparing First Character to '\0' Instead of using the string functions, it is more efficient to check for empty C-strings by comparing the first character of the string to null or '\0'. This method reduces the function overhead and makes the code ...
🌐
Northern Illinois University
faculty.cs.niu.edu › ~winans › CS501 › Notes › cstrings.html
C Strings
A valid C string requires the presence of a terminating "null character" (a character with ASCII value 0, usually represented by the character literal '\0'). Since char is a built-in data type, no header file needs to be included to create a C string.
Find elsewhere
🌐
Wikipedia
en.wikipedia.org › wiki › Empty_string
Empty string - Wikipedia
January 16, 2026 - In formal language theory, the ... of characters such as letters, digits or spaces. The empty string is the special case where the sequence has length zero, so there are no symbols in the string....
🌐
Reddit
reddit.com › r/learnprogramming › what is the best way to check for a blank string?
r/learnprogramming on Reddit: What is the best way to check for a blank string?
December 2, 2015 -

Perhaps this is trivial, but I got to wondering what is considered the "best" way to check for a blank string. I was specifically thinking of Javascript, although this could be applied to a number of languages. (Any C-style language) I thought up a couple solutions...

if (foo == "") ...

if (foo.length() == 0) ...

Not included in Javascript, but in languages that have it:

if (foo.isEmpty()) ...

Which of these is generally considered the most elegant/readable? Is it the single-purpose function, or a general-purpose function with a comparison? Or does it just not matter?

🌐
Nim Forum
forum.nim-lang.org › t › 3806
How to get the address of string ""
We cannot provide a description for this page right now
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › std-string-empty-in-cpp
std::string::empty() in C++ - GeeksforGeeks
July 23, 2025 - This function is used to check if a string is empty, i.e., whether its length is 0 or not, and returns a boolean value true if the string is empty otherwise, it returns false.
🌐
Reddit
reddit.com › r/cprogramming › string variable unexpectedly becomes an empty string
r/cprogramming on Reddit: string variable unexpectedly becomes an empty string
February 27, 2024 -

For some reason, the name variable becomes empty even though I gave it an input.

Code:

#include <stdio.h>

int main(){
    
    char name[16];
    short unsigned int age;

    printf("What is your name? ");
    scanf("%s", &name);

    printf("How old are you? ");
    scanf("%u", &age);

    printf("Hello, %s.\n", name);
    printf("You are %u years old\n", age);

    return 0;
}

Terminal:

What is your name? Momus
How old are you? 99
Hello, .
You are 99 years old

I seems that the value for name was changed in the part somewhere in the part that prints "How old are you? " and the scanf() for the value of age because it works when I do this.

Code:

#include <stdio.h>

int main(){
    
    char name[25];
    short unsigned int age;

    printf("What is your name? ");
    scanf("%s", &name);
    printf("Hello, %s.\n", name);

    printf("How old are you? ");
    scanf("%u", &age);
    printf("You are %u years old\n", age);

    return 0;
}

Terminal:

What is your name? Momus
Hello, Momus.
How old are you? 99
You are 99 years old

Does anyone know what happened? How do I make it so that the first one will show the input? Thanks!

🌐
Cppreference
en.cppreference.com › w › cpp › string › basic_string.html
std::basic_string - cppreference.com
The elements of a basic_string are stored contiguously, that is, for a basic_string s, &*(s.begin() + n) == &*s.begin() + n for any n in [​0​, s.size()), and *(s.begin() + s.size()) has value CharT() (a null terminator)(since C++11); or, equivalently, a pointer to s[0] can be passed to functions that expect a pointer to the first element of an array(until C++11)a null-terminated array(since C++11) of CharT.
🌐
Cprogramming
cboard.cprogramming.com › c-programming › 74027-how-test-if-string-empty.html
How to test if a string is empty
January 1, 2006 - [0] == '\0') { Because you are testing if the first character of the array is '\0'. Also, you could use strchr to find the linefeed instead of the for loop. ... Oh I see, I didn't think about the fact that a string is an array and that if it's empty the first value would read '\0'.... Thanks again cwr, you've been a great help.
🌐
GitHub
github.com › dotnet › roslyn › discussions › 73123
Should we optimize or deprecate `string.Empty` in C#? · dotnet/roslyn · Discussion #73123
April 20, 2024 - There are 2 representation for an empty string in C#, "" and string.Empty. Both finally refer to the same single string instance after compiled by JIT, but string.Empty is less optimized than "" in some context by Roslyn because it is just a static field.
Author   dotnet
🌐
Go Packages
pkg.go.dev › strings
strings package - strings - Go Packages
Fields splits the string s around each instance of one or more consecutive white space characters, as defined by unicode.IsSpace, returning a slice of substrings of s or an empty slice if s contains only white space. Every element of the returned slice is non-empty.
🌐
Rosetta Code
rosettacode.org › wiki › Empty_string
Empty string - Rosetta Code
1 week ago - This fixes that. CMP.L A0,(SP) ;compare the current A0 with the original value. BEQ StringIsEmpty ;if they are equal, then nothing was read besides the terminator. Therefore the string is empty.
🌐
Codemia
codemia.io › knowledge-hub › path › how_do_i_test_if_a_string_is_empty_in_objective-c
How do I test if a string is empty in Objective-C?
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises
🌐
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.
🌐
Sabe
sabe.io › blog › c-check-string-empty
How to Check if a String is Empty in C | Sabe
March 19, 2022 - The best way to check if a string is empty is to use the strlen() function.