The null character, abbreviated NUL, is a control character with the value zero.
Questions tagged [null-character]
101 questions
67
votes
5 answers
Reading null delimited strings through a Bash loop
I want to iterate through a list of files without caring about what characters the filenames might contain, so I use a list delimited by null characters. The code will explain things better.
# Set IFS to the null character to hopefully change the…

Matthew
- 6,351
- 8
- 40
- 53
38
votes
5 answers
Assign string containing null-character (\0) to a variable in Bash
While trying to process a list of file-/foldernames correctly (see my other questions) through the use of a NULL-character as a delimiter I stumbled over a strange behaviour of Bash that I don't understand:
When assigning a string containing one or…

antiplex
- 938
- 2
- 12
- 17
31
votes
4 answers
What is the difference between (char)0 and '\0'? in C
What is the difference between using (char)0 and '\0' to denote the terminating null character in a character array?

Sathya
- 525
- 1
- 8
- 15
24
votes
5 answers
What could cause an XML file to be filled with null characters?
This is a tricky question. I suspect it will require some advanced knowledge of file systems to answer.
I have a WPF application, "App1," targeting .NET framework 4.0. It has a Settings.settings file that generates a standard App1.exe.config file…

Kyle Delaney
- 11,616
- 6
- 39
- 66
11
votes
2 answers
C++: About null characters
There are two string variables, m and n:
#include
string m = "0100700\0"
cout << m.size() << endl; // it prints: 7
string n;
n += "0100700"
n += '\0';
cout << n.size() << endl; // it prints: 8
I supposed that both had 8 characters, but m…
user3764269
10
votes
4 answers
Use of null character in strings (C++)
I am brushing up on my C++ and stumbled across a curious behavior in regards to strings, character arrays, and the null character ('\0'). The following code:
#include
using namespace std;
int main() {
cout << "hello\0there"[6] <<…

ewok
- 20,148
- 51
- 149
- 254
9
votes
3 answers
difference between "\0" and '\0'
I am trying to understand following piece of code, but I am confused between "\0" and '\0'.I know its silly but kindly help me out
#define MAX_HISTORY 20
char *pStr = "\0";
for(x=0;x

Fermi
- 115
- 1
- 6
8
votes
1 answer
bash “read -a” looping on null delimited string variable
I've been reading up on this post: bash "for in" looping on null delimited string variable
to see if I would be able to handle arbitrary text containing spaces inside an array.
Based on the post above this works fine:
while IFS= read -r -d '' myvar;…

Tore H-W
- 181
- 4
8
votes
4 answers
Java BufferedWriter Creating Null Characters
I've been using Java's BufferedWriter to write to a file to parse out some input. When I open the file after, however, there seems to be added null characters. I tried specifying the encoding as "US-ASCII" and "UTF8" but I get the same result.…

SortingHat
- 727
- 3
- 15
- 30
7
votes
2 answers
store non-nul terminated C string constant in C++
Before anyone says, "DON'T DO THIS as it is really bad".
I understand the reasons for having a NUL terminated string.
I know one can state something like
char mystr[] = { 'm', 'y', ' ', 's', 't', 'r', 'i', 'n', 'g'};
However, the convenience of…

Adrian
- 10,246
- 4
- 44
- 110
5
votes
7 answers
How best to determine if a String contains only null characters?
What's the right way to check if a string contains null characters only?
String s = "\u0000";
if(s.charAt(0) == 0) {
System.out.println("null characters only");
}
Or
String s = "\0\0";
for(int i = 0; i < s.length(); i++) {
if(s.charAt(i) ==…

tusharRawat
- 719
- 10
- 24
5
votes
4 answers
Is it possible to read null characters correctly using fgets or gets_s?
Suppose I want to read from stdin, and let the user input strings that contain null characters. Is this possible with string-input functions like fgets or gets_s? Or do I have to use e.g. fgetc or fread?
Someone here wanted to do this.

anatolyg
- 26,506
- 9
- 60
- 134
5
votes
2 answers
Inconsistent behavior of fscanf() across different compilers (consuming trailing null character)
I wrote a complete application in C99 and tested it thoroughly on two GNU/Linux-based systems. I was surprised when an attempt to compile it using Visual Studio on Windows resulted in the application misbehaving. At first I couldn't assert what was…

rhino
- 13,543
- 9
- 37
- 39
5
votes
2 answers
SQLite strings with NUL
Can strings in SQLite 3 include NUL characters?
If the answer to 1 is "yes", how can they be written in SQL queries? SQLite doesn't seem to have chr or char functions.

Alexey Romanov
- 167,066
- 35
- 309
- 487
4
votes
4 answers
fgetc null terminator
I'm doing an exercise in K&R:
Write a program detab that replaces tabs in the input with the proper number of blanks to space to the next tab stop.
And this is what I have so far (w/o error checking on the file):
#include
#define tab…

mwlow
- 141
- 10