null-character

Use of null character in strings (C++)

一曲冷凌霜 提交于 2019-12-03 12:23:35
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 <iostream> using namespace std; int main() { cout << "hello\0there"[6] << endl; char word [] = "hello\0there"; cout << word[6] << endl; string word2 = "hello\0there"; cout << word2[6] << endl; return 0; } produces the output: > t > t > What is going on behind the scenes? Why does the string literal and the declared char array store the 't' at index 6 (after the internal '\0' ), but the declared string does not? sean From what I

What is the difference between (char)0 and '\\0'? in C

浪子不回头ぞ 提交于 2019-11-30 01:30:52
What is the difference between using (char)0 and '\0' to denote the terminating null character in a character array? The backslash notation in a character literal allows you to specify the numeric value of a character instead of using the character itself. So '\1' [*] means "the character whose numeric value is 1", '\2' means "the character whose numeric value is 2", etc. Almost. Due to a quirk of C, character literals actually have type int , and indeed int is used to handle characters in other contexts too, such as the return value of fgetc . So '\1' means "the numeric value as an int, of

What is the difference between (char)0 and '\0'? in C

梦想的初衷 提交于 2019-11-28 22:19:29
问题 What is the difference between using (char)0 and '\0' to denote the terminating null character in a character array? 回答1: The backslash notation in a character literal allows you to specify the numeric value of a character instead of using the character itself. So '\1' [*] means "the character whose numeric value is 1", '\2' means "the character whose numeric value is 2", etc. Almost. Due to a quirk of C, character literals actually have type int , and indeed int is used to handle characters

Reading null delimited strings through a Bash loop

泪湿孤枕 提交于 2019-11-27 17:42:27
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 for..in # delimiter from the space character (sadly does not appear to work). IFS=$'\0' # Get null delimited list of files filelist="`find /some/path -type f -print0`" # Iterate through list of files for file in $filelist ; do # Arbitrary operations on $file here done The following code works when reading from a file, but I need to read from a

Assign string containing null-character (\\0) to a variable in Bash

别等时光非礼了梦想. 提交于 2019-11-27 07:49:24
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 more NULL-character to a variable, the NULL-characters are lost / ignored / not stored. For example, echo -ne "n\0m\0k" | od -c # -> 0000000 n \0 m \0 k But: VAR1=`echo -ne "n\0m\0k"` echo -ne "$VAR1" | od -c # -> 0000000 n m k This means that I would need to write that string to a file (for example, in /tmp) and read it back from there if piping