Check if the first character is '\0'. You should also probably check if your pointer is NULL.

char *c = "";
if ((c != NULL) && (c[0] == '\0')) {
   printf("c is empty\n");
}

You could put both of those checks in a function to make it convenient and easy to reuse.

Edit: In the if statement can be read like this, "If c is not zero and the first character of character array 'c' is not '\0' or zero, then...".

The && simply combines the two conditions. It is basically like saying this:

if (c != NULL) { /* AND (or &&) */
    if (c[0] == '\0') {
        printf("c is empty\n");
    }
}

You may want to get a good C programming book if that is not clear to you. I could recommend a book called "The C Programming Language".

The shortest version equivalent to the above would be:

if (c && !c[0]) {
  printf("c is empty\n");
}
Answer from codemaker on Stack Overflow
🌐
Quora
quora.com › How-do-I-check-if-a-char-array-is-empty
How to check if a char array is empty - Quora
... “Empty” as C-style string: first element is the null terminator ('\0'), so the string contents are empty. “All elements zero/blank”: every element equals '\0' or some whitespace value.
Discussions

How to check if C string is empty - Stack Overflow
I want the program to stop looping if the user just presses enter without entering anything. ... Since C-style strings are always terminated with the null character (\0), you can check whether the string is empty by writing More on stackoverflow.com
🌐 stackoverflow.com
c - Best way to check if a character array is empty - Stack Overflow
The third method doesn't check whether a character array is empty; it ensures that a character array is empty. ... The second one is fastest. Using strlen will be close if the string is indeed empty, but strlen will always iterate through every character of the string, so if it is not empty, ... More on stackoverflow.com
🌐 stackoverflow.com
How to check if String is empty in C - Stack Overflow
Learn more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I have a void function which take the string from a global variable and prints them. The problem is that the void function prints a message/does stuff even if the string is empy. so if the global variable is empt it just prints "message is:" i only want to do something if the string has characters. what i want to do is to check ... More on stackoverflow.com
🌐 stackoverflow.com
c - How can I check if a char * is empty? - Stack Overflow
What is "empty" ? Initialize it to NULL in the beginning and check *name == NULL. Yet it looks like XY-problem to me. This whole approach is going to give you troubles in the future. Eugene Sh. – Eugene Sh. 2018-06-01 13:47:20 +00:00 Commented Jun 1, 2018 at 13:47 · strlen works by counting the number of characters up untill the null char '\0' You could check to see if ... More on stackoverflow.com
🌐 stackoverflow.com
June 1, 2018
🌐
Cprogramming
cboard.cprogramming.com › c-programming › 59741-how-check-if-char*-empty-null.html
How to check if char* is empty or null??
December 14, 2004 - It is only empty if it doesnt contain a character (except \0), if the value is " " then it contains a space, which is a character. Check if its NULL, Empty (only '\0'), if its not either see if it contains other characters besides a white space.
🌐
Sabe
sabe.io › blog › c-check-string-empty
How to Check if a String is Empty in C - Sabe.io
March 19, 2022 - CLIKE#include <stdio.h> #include ... 0; } Another way you can check if a string is empty is to check if the first character of the string is a null character....
🌐
Programiz
programiz.com › cpp-programming › library-function › cctype › isblank
C++ isblank() - C++ Standard Library
The isblank() function returns non zero value if ch is a blank character, otherwise returns zero. #include <cctype> #include <iostream> #include <cstring> using namespace std; int main() { char str[] = "Hello, I am here."; int count = 0; for (int i=0; i<=strlen(str); i++) { if (isblank(str[i])) ...
🌐
Cplusplus
cplusplus.com › reference › cctype › isblank
Cplusplus
In C++, a locale-specific template version of this function (isblank) exists in header <locale>. Compatibility note: Standardized in C99 (C++11). ... Character to be checked, casted to an int, or EOF. A value different from zero (i.e., true) if indeed c is a blank character.
Find elsewhere
🌐
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. The strlen() function takes the string as an argument and returns the total number of characters in a given string, so if that function returns 0 then the given ...
🌐
Educative
educative.io › answers › what-is-isblank-in-cpp
What is isblank() in C++?
We use the isblank() function in C++ to determine if a given character is a blank character.
🌐
Arduino Forum
forum.arduino.cc › projects › programming
How to check if a char array is blank (or at least 20 ?)<< SOLVED>> - Programming - Arduino Forum
January 21, 2022 - This is a small test sketch : I only want to print these lines if they contain anything: Would anyone please assist me. Many thanks in advance. char line0 [19]; char line1 [19]; char line2 [19]; char line3 [19]; void setup() { Serial.begin(9600); while (!Serial); // wait for serial connection ...
🌐
C For Dummies
c-for-dummies.com › blog
Null Versus Empty Strings | C For Dummies Blog
August 12, 2017 - #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. It has a single element, a null character.
🌐
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?
February 4, 2017 -

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!

🌐
Arduino Forum
forum.arduino.cc › projects › programming
Empty value detection for char* type variable - Programming - Arduino Forum
September 20, 2022 - Hi all, I just simply want to detect whether a char * variable is empty or not. For example, char* token =""; If( token != '\0' ){ Serial.println("okay"); }else{ Serial.println("Something is wrong!!!!"); } But it wi…
🌐
Silicon Cloud
silicloud.com › home › how to determine if a char array is empty in c language?
How to determine if a char array is empty in C language? - Blog - Silicon Cloud
March 28, 2024 - #include <stdio.h> #include <stdbool.h> bool isCharArrayEmpty(char arr[], int size) { for (int i = 0; i < size; i++) { if (arr[i] != '\0') { return false; // 如果数组中有一个元素不是空字符,则返回false } } return true; // 如果数组中所有元素都是空字符,则返回true } int main() { char arr1[] = {'\0', '\0', '\0'}; char arr2[] = {'a', 'b', 'c'}; if (isCharArrayEmpty(arr1, sizeof(arr1)/sizeof(arr1[0]))) { printf("arr1 is empty\n"); } else { printf("arr1 is not empty\n"); } if (isCharArrayEmpty(arr2, sizeof(arr2)/sizeof(arr2[0]))) { printf("arr2 is empty\n"); } else { printf("arr2 is not empty\n"); } return 0; } In the above code, the isCharArrayEmpty function is used to check if a char array is empty.
🌐
Reddit
reddit.com › r/cpp_questions › how does char x = 0 work?
r/cpp_questions on Reddit: how does char x = 0 work?
August 29, 2020 -

i saw 0 being used in place for both initializing an empty character which would be ‘’ and for checking when a zero terminated array of char or a string ends which should check for ‘\0’?

So what does the char 0 even do?

also how does it relate to this......

A test of a numeric value (e.g., while (*p) in count_x()) is equivalent to comparing the value to 0 (e.g., while (*p!=0)). A test of a pointer value (e.g., if (p)) is equivalent to comparing the value to nullptr (e.g., if (p!=nullptr))

I assume that putting if (variable) just means if (variable != the empty version of the type) .....

and the empty version of the types would be 0 for int, 0.0 for double,

‘’ , ‘\0’, and 0 for char

NULL, nullptr......others for other types?

🌐
Lazarus
forum.lazarus.freepascal.org › index.php
know if a text (or char) field is empty
May 26, 2013 - know if a text (or char) field is empty · Free Pascal · Website · Downloads · Wiki · Documentation · Bugtracker · Mailing List · Lazarus · Website · Downloads (Laz+FPC) Packages (OPM) FAQ · Wiki · Documentation (RTL/FCL/LCL) Bugtracker · CCR Bugs ·