Questions tagged [null-character]

The null character, abbreviated NUL, is a control character with the value zero.

101 questions
2
votes
2 answers

char array with pointer in c with %s

i have these two c programming code .They are identical except for one step and because of that their output is totally different please help me why is this happening main() { char ch[10]="123456"; char *p; int…
2
votes
3 answers

Strlen Function behavior on single character

Here is my code: void func(char c) { char * ptr = &c; size_t len = strlen(ptr); printf("len - %d\n", len); } len is always printed as 1. strlen(..) determines the length of a char array by finding the null character (\0) at the end of…
viv
  • 45
  • 3
2
votes
3 answers

string XOR function in C: How to deal with null characters?

I'm writing a program in C that reads text from a file, takes a password as an argument, creates a string of the same length as the input string, and does a char-by-char XOR operation of it, outputting encoded text to another file, which can then be…
2
votes
0 answers

Null Character in javascript - Mongo

I am trying to process some data stored in MongoDB. These are integers packed in a byte string. Something of the form: "touch_data" : "\u0000\u0000\u0000\u0000\u0000\u0000\u0000" If I take this string and compute its length, mongo's js engine tells…
user1151659
  • 132
  • 11
2
votes
2 answers

Why is "%s" format specifier working even for a character array without `\0` & printing all its elements at once?

Look at the following code: #include int main(void) { char name[7]={'E','R','I','C'}; printf("%s",name); } It outputs the entire name ERIC.Why is it so?Isn't %s supposed to work only if we initialize the character array name as…
Rüppell's Vulture
  • 3,583
  • 7
  • 35
  • 49
2
votes
1 answer

Printing a string with null characters in it

I take as input a string with spaces in it and replace the spaces with the NULL character '\0'. When I print the string now, I expect only the part till the first NULL character which was the first space earlier but I am getting the original…
pikachu
  • 602
  • 8
  • 17
1
vote
1 answer

Is there a way I can see '\0' (null character) in Visual Studio's text editor?

I am making my own file format. It looks like so: { { 0 GameObject0 { { 0, 0, 0 }
1
vote
1 answer

Can the "null character" be represented as a multibyte value in C language?

The ANSI X3.159-1989 "Programming Language C" standard states in the chapter "5.2.1.2 - Multibyte characters" that: For both [source and execution] character sets the following shall hold: A byte with all bits zero shall be interpreted as a null…
CoSalamander
  • 121
  • 7
1
vote
0 answers

Why is the zero termination ignored when I assign it after initializing the string?

I arrived at two different cases but was not able to arrive at a conclusion that what was actually happening inside. Can anyone please explain? CASE 1: #include using namespace std; int main() { string my_string = "This is a sam\0ple…
1
vote
1 answer

why these two character arrays won't concatenate properly?(C Programming)

char *program_working_dir; char backup_dir[9]="/Backups/"; // getting the current working directory program_working_dir = getcwd(NULL, 0); if (program_working_dir == NULL){ printf("Failed to get working directory( take_backup function )\n"); …
ramixix
  • 33
  • 5
1
vote
2 answers

Grep with a regex character range that includes the NULL character

When I include the NULL character (\x00) in a regex character range in BSD grep, the result is unexpected: no characters match. Why is this happening? Here is an example: $ echo 'ABCabc<>/ă' | grep -o [$'\x00'-$'\x7f'] Here I expect all characters…
1
vote
0 answers

Why does JsonConvert.SerializeObject put /u000 and other random escape characters into my serialization

I am reading all installed software from the registry. It is working fine on all computers tested except for one which is giving me the following problem. It reads the data from the registry correctly and puts the proper data into the proper fields…
Chris Dunlop
  • 135
  • 1
  • 13
1
vote
5 answers

Why is this still counting spaces within a String?

I'm just starting to code and I need help figuring out why this loop counts spaces within a string. To my understanding, this code should tell the computer to not count a space "/0" and increase count if the loop goes through the string and it's any…
1
vote
1 answer

How to enter a NULL CHARACTER in file name on mac?

I want to create a file with null character in its name on mac. filename like - abc\0ds.txt I tried creating a file with name 'abc\0ahd.txt' but \0 in the name is not really unicode null character. It is some other character. I want to create a file…
Himanshu Sharma
  • 101
  • 1
  • 4
1
vote
2 answers

Remove null character embedded in string

I have a c++ string with embedded '\0' characters. I have a function replaceAll() which should replace all occurrences of a pattern with another pattern. For "normal" strings it works fine. However, when I try to find the '\0' character my function…
LeviX
  • 3,096
  • 3
  • 28
  • 41