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...
🌐
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> ...
🌐
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.
🌐
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.
🌐
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.
Find elsewhere
🌐
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.
🌐
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!

🌐
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.
🌐
W3Schools
w3schools.com › cpp › ref_string_empty.asp
C++ String empty() Function
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. It returns 1 if the string is empty, otherwise 0. ... Read more about ...
🌐
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').
🌐
C For Dummies
c-for-dummies.com › blog
Null Versus Empty Strings | C For Dummies Blog
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 null[5]; if( strcmp(empty,null)==0 ) puts("Strings are the same"); else puts("Strings are not the same"); return(0); } Array empty[] at Line 6 is created as an empty 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.
🌐
MathWorks
es.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
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 more efficient.
🌐
Silicon Cloud
silicloud.com › home › how to determine if a string is empty in c language?
How to determine if a string is empty in C language? - Blog - Silicon Cloud
March 21, 2024 - There are several ways in C language to determine if a string is empty. Check the length of the string using the strlen function to see if it equals 0. if (strlen(str) == 0) { // 字符串为空 } else { // 字符串不为空 } Use the strcmp function to determine if a string is equal to […]
🌐
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.