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
๐ŸŒ
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...
๐ŸŒ
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.
๐ŸŒ
Cprogramming
cboard.cprogramming.com โ€บ c-programming โ€บ 74027-how-test-if-string-empty.html
How to test if a string is empty
if (string[0] == '\0') Unnoticeably... and you couldn't possibly argue that it's impractical to check string length. Besides... it give him a heads up on how to handle it when he, perhaps, has to deal with strings that don't terminate with a null. Besides comparing to two empty quotes.
๐ŸŒ
C For Dummies
c-for-dummies.com โ€บ blog
Null Versus Empty Strings | C For Dummies Blog
Therefore the string length is wherever the next random null character is found in memory. By the way, this function wouldnโ€™t work most other programming languages where variables must be initialized before you assault them with a function. Though C doesnโ€™t really have official typing for empty and null strings, you can still tell the difference between them: compare.
๐ŸŒ
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: CLIKE#include <stdio.h> #include <string.h> ...
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 - To get the length of a string, we can use the strlen method. This method takes one string as its argument and returns the length for that string. If the return value of this function is 0, then the string is empty.
๐ŸŒ
Python Examples
pythonexamples.org โ€บ c โ€บ how-to-check-if-string-is-empty
How to Check if String is Empty in C
To check if a string is empty in C, you can use the strlen() function from the string.h library.
๐ŸŒ
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.
๐ŸŒ
Reddit
reddit.com โ€บ r/c_programming โ€บ how to detect an empty string in standard input?
r/C_Programming on Reddit: How to detect an empty string in standard input?
October 12, 2016 -

Im not sure if im correct in calling it an empty string but i thought it would be.

#include "stdio.h"
#include "string.h"
#include "stdlib.h"

int main(void)
{
	char input[136];
	char partOne[6];
	char partTwo[128];
	fgets(input, 136, stdin); // Now i input "Hello " or "Hello"
	sscanf(input, "%5s %127s", partOne, partTwo);
	if(!strcmp(partTwo, ""))
		printf("%s\n", "YES");
	return 0;
}

if I input "Hello " or "Hello" I want to detect that the char array partTwo has an empty string (i don't know what else to call it) but since the check fails then I think its not an empty string so what is it?

If I input "Hello" or "Hello " what is the value of partTwo so I can test for it using strcmp

Thank you!

๐ŸŒ
W3Schools
w3schools.com โ€บ cpp โ€บ ref_string_empty.asp
C++ String empty() Function
Find out if a string is empty or not: string txt1 = "Hello World!"; string txt2 = ""; cout << txt1.empty(); cout << txt2.empty(); Try it Yourself ยป ยท The empty() function checks wheter a string is empty or not.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c++ โ€บ std-string-empty-in-cpp
std::string::empty() in C++ - GeeksforGeeks
July 23, 2025 - The std::string::empty() function in C++ is a predefined member function of the std::string class template. 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 ...
๐ŸŒ
Iditect
iditect.com โ€บ program-example โ€บ how-to-check-if-c-string-is-empty.html
How to check if C string is empty
In C, a string is typically represented as an array of characters terminated by a null character (\0). To check if a C string is empty, you can verify if the first character is 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
Each method has tradeoffs in readability, efficiency, and use cases. The simplest and most efficient way to check for an empty string is to verify if its first character is the null terminator ('\0').
๐ŸŒ
Rosetta Code
rosettacode.org โ€บ wiki โ€บ Empty_string
Empty string - Rosetta Code
1 week ago - REM assign an empty string to a variable: var$ = "" REM Check that a string is empty: IF var$ = "" THEN PRINT "String is empty" REM Check that a string is not empty: IF var$ <> "" THEN PRINT "String is not empty" using System; namespace EmptyString ...
๐ŸŒ
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?

๐ŸŒ
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 ...