In addition to Will Dean's version, the following are common for whole buffer initialization:

Copychar s[10] = {'\0'};

or

Copychar s[10];
memset(s, '\0', sizeof(s));

or

Copychar s[10];
strncpy(s, "", sizeof(s));
Answer from Matt Joiner on Stack Overflow
๐ŸŒ
C For Dummies
c-for-dummies.com โ€บ blog
Null Versus Empty Strings | C For Dummies Blog
A null string has no values. Itโ€™s an empty char array, one that hasnโ€™t been assigned any elements. The string exists in memory, so itโ€™s not a NULL pointer.
๐ŸŒ
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.
๐ŸŒ
Northern Illinois University
faculty.cs.niu.edu โ€บ ~winans โ€บ CS501 โ€บ Notes โ€บ cstrings.html
C Strings
The individual characters that ... part of the string, and their contents are irrelevant. A "null string" or "empty string" is a string with a null character as its first character:...
๐ŸŒ
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.
๐ŸŒ
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]. ...
Find elsewhere
๐ŸŒ
Cprogramming
cboard.cprogramming.com โ€บ cplusplus-programming โ€บ 12230-setting-empty-string.html
Setting an empty string
They will both work, but perform ... way but it depends on what you want to do as to which one you should use. A truly "empty" string would be char *pString = NULL;...
๐ŸŒ
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!

๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
Edaboard
edaboard.com โ€บ digital design and embedded programming โ€บ pc programming and interfacing
make a string empty in C | Forum for Electronics
September 15, 2011 - I done this to do so. while(some_cond) { string=(char *)malloc(20); while(cond) { string[index]=assigne_something; ++index; } } but I think it is a bad idea. Is there any better idea to do it ... I need to keep this string empty every time i execute the loop.
๐ŸŒ
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.