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
Itโ€™s just absent any elements. 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.
๐ŸŒ
Northern Illinois University
faculty.cs.niu.edu โ€บ ~winans โ€บ CS501 โ€บ Notes โ€บ cstrings.html
C Strings
However, an array of char is not by itself a C string. 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 ...
๐ŸŒ
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
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...
๐ŸŒ
Cprogramming
cboard.cprogramming.com โ€บ c-programming โ€บ 74027-how-test-if-string-empty.html
How to test if a string is empty
... has to deal with strings that don't terminate with a null. humm -- strlen() only works with null-terminated strings, or did I misunderstand you? ... There's no such thing as a string in C that doesn't end in a null termination. That is what makes a string a string.
๐ŸŒ
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. This built-in function returns the length of a string when you pass in the string as an argument.
Find elsewhere
๐ŸŒ
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!

๐ŸŒ
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 - If you run this program, it will print the below output: ... We can also check if the first character of a string is a null character or not, i.e. if it is \0 or not. All strings in C are terminated with a null character.
๐ŸŒ
Quora
quora.com โ€บ How-do-you-initialize-char*-to-an-empty-string-in-C
How to initialize char* to an empty string in C - Quora
Answer (1 of 8): An empty string in C - meaning one that would be a legal-formed string that would be regarded as a string of zero-length by the string.h string functions and other functions that operate on strings - is simply [code ]""[/code]. ...
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Empty_string
Empty string - Wikipedia
January 16, 2026 - Even a string of length zero can require memory to store it, depending on the format being used. In most programming languages, the empty string is distinct from a null reference (or null pointer) because a null reference points to no string at all, not even the empty string.
๐ŸŒ
Rosetta Code
rosettacode.org โ€บ wiki โ€บ Empty_string
Empty string - Rosetta Code
1 week ago - Empty string is "" and checking for empty strings (or empty lists) can be done with the nu command. ... In C the strings are char pointers. A string terminates with the null char (U+0000, '\0'), which is not considered part of the string.
๐ŸŒ
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.
๐ŸŒ
Silicon Cloud
silicloud.com โ€บ home โ€บ how to define an empty string in the c programming language?
How to define an empty string in the C programming language? - Blog - Silicon Cloud
March 21, 2024 - In the C language, an empty string is a string with a length of 0, and can be defined in two ways: Define an empty string using a character array: char str[1] = ""; Define an empty string using a character pointer. char *str = ""; No matter what method you use, you can assign [โ€ฆ]
๐ŸŒ
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 ...
๐ŸŒ
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 - In C, we can check if a string is empty using various methods, such as checking the first character, using the strlen() function, or comparing it with an empty string.