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
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') ...
๐ŸŒ
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.
๐ŸŒ
Northern Illinois University
faculty.cs.niu.edu โ€บ ~winans โ€บ CS501 โ€บ Notes โ€บ cstrings.html
C Strings
The length of a null string is ... any other array, the subscript operator may be used to access the individual characters of a C++ string: cout << s3[1] << endl; // Prints the character 'e', the second character in the string "Hello"...
๐ŸŒ
Cprogramming
cboard.cprogramming.com โ€บ c-programming โ€บ 74027-how-test-if-string-empty.html
How to test if a string is empty
[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 ...
๐ŸŒ
TutorialKart
tutorialkart.com โ€บ c-programming โ€บ how-to-check-if-a-string-is-empty-in-c
How to Check if a String is Empty in C - Examples
February 21, 2025 - We call strlen(str) to get the length of the string. If the length is zero, we print "The string is empty.". Otherwise, we print "The string is not empty.". The string is empty. In this example, we compare the string with an empty string using strcmp() from string.h.
๐ŸŒ
Sabe
sabe.io โ€บ blog โ€บ c-check-string-empty
How to Check if a String is Empty in C | Sabe
March 19, 2022 - It will naturally return the number of characters in a string, and so to check if it is empty, simply check if the length of the string is 0. Here's an example of how to use the strlen() function:
Find elsewhere
๐ŸŒ
CodeVsColor
codevscolor.com โ€บ c program to check if a string is empty or not - codevscolor
C program to check if a string is empty or not - CodeVsColor
June 14, 2021 - It returns 0 if it is empty, else it returns 1. isStringEmpty checks the size of the string by using strlen method. It checks the output of this method. If it is 0, i.e. string is empty, it returns 0.
๐ŸŒ
DEV Community
dev.to โ€บ biraj21 โ€บ empty-strings-and-zero-length-arrays-how-do-we-store-nothing-1jko
Empty Strings and Zero-length Arrays: How do We Store... Nothing? - DEV Community
June 25, 2024 - When you create an empty string in C, you are essentially allocating a string that points to a memory location that stores the null character. This is akin to reserving a seat at a table for a ghost. The chair is there, the place is set, but nobody's coming to dinner. Reminds me of my last date. ... In this example, emptyString is an array with a single element (notice the [1]in the declaration), which is the null terminator.
๐ŸŒ
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...
๐ŸŒ
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!

๐ŸŒ
Reactgo
reactgo.com โ€บ home โ€บ how to check if a string is empty in c
How to check if a string is empty in C | Reactgo
March 8, 2023 - To check if a given string is empty or not, we can use the strlen() function in C.
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Empty_string
Empty string - Wikipedia
January 16, 2026 - The empty string is a legitimate string, upon which most string operations should work. Some languages treat some or all of the following in similar ways: empty strings, null references, the integer 0, the floating point number 0, the Boolean value false, the ASCII character NUL, or other such values.
๐ŸŒ
Iditect
iditect.com โ€บ program-example โ€บ how-to-check-if-c-string-is-empty.html
How to check if C string is empty
If it is, the function returns 1, indicating that the string is empty. Another method is to use the strlen function from the C standard library (string.h). This function returns the length of the string (excluding the null terminator).
๐ŸŒ
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
Before checking if a string is empty, we must define "empty." In C, "empty" can have nuanced interpretations depending on context: Strictly Empty: The string contains only the null terminator ('\0'). For example:
๐ŸŒ
7-Zip Documentation
documentation.help โ€บ C-Cpp-Reference โ€บ empty.html
empty - C/C++ Reference Documentation
#include <string> bool empty() const; The empty() function returns true if the string has no elements, false otherwise. For example: string s1; string s2(""); string s3("This is a string"); cout.setf(ios::boolalpha); cout << s1.empty() << endl; cout << s2.empty() << endl; cout << s3.empty() ...