Questions tagged [null-terminated]

A string that ends with (and does not include) a "null" (ASCII 0) byte, as used by the C language

The C language doesn't have a built-in string type, instead strings are represented by a contiguous sequence of characters followed by a null-terminator (a character with value zero) and are referred to by a pointer to the first character of the sequence. The length of the string is therefore implied by the position of the null terminator, rather than being stored explicitly. Operations on null-terminated strings use a pointer to the sequence and interpret all the characters up to the null-terminator as the contents of the string.

This contrasts with string types in other languages which might be represented by an abstract data type or as a pointer to data where the length is stored in one or more bytes at the start of the string.

206 questions
-1
votes
2 answers

Weird characters when trying to grab char * from fstream

I am trying to read 4 characters at a specific position from a file. The code is simple but the result is really confusing: fstream dicomFile; dicomFile.open(argv[1]); dicomFile.seekg(128,ios::beg); char * memblock = new char…
DoubletopLei
  • 11
  • 1
  • 2
-1
votes
1 answer

fread() doesn't add null terminator [C], can't add one because I have a pointer to a pointer

Line 37, I am trying to print the data in my buffer pointer. But I have a pointer (gdhFileProp->buffer) to a pointer (char* buffer). Since I am using fread(), It doesn't add the \0 when reading the file contents. And since it's a pointer to a…
Greg M
  • 954
  • 1
  • 8
  • 20
-1
votes
2 answers

\0 character in istream::getline()

What happens if a file contains a \0 character when using istream::getline()? Will be it be omitted or still assigned into a field in the string buffer?
Niklas R
  • 16,299
  • 28
  • 108
  • 203
-2
votes
1 answer

Using BDE API (BdiCopyTable) with Delphi 10.1 Berlin

The following code compiles and workes using Delphi 5 but not using Delphi 10.1 Berlin; function CopyTable(const tSource: TwwTable; const Destination: string): DBIResult; var pSourceTableName, pDestination: array[0..DBIMAXTBLNAMELEN] of…
S L Bentall
  • 257
  • 2
  • 11
-2
votes
3 answers

Remove trailing NULL terminator

I have a large char array that is filled with 0's. I read an incoming file from a socket and place it's contents in the buffer. I can't write the buffer with all of the '\0's in it, so I allocate a new buffer with the correct size and to write. I…
DMP
  • 973
  • 1
  • 7
  • 13
-2
votes
3 answers

Null termination of C string

Is it right to say that the null terminating C string is automatically added by the compiler in general? So in the following example: char * str = "0124"; printf("%x", str[str[3] - str[2] + str[4]]); the output is always 32? Thanks.
rok
  • 9,403
  • 17
  • 70
  • 126
-3
votes
1 answer

input char* without using string library

I'd like to do the following, but without including string: #include #include using namespace std; int main() { string s1,s2; char c; cout<<"input a string: "<>s1; cout<<"input a character:…
Rik
  • 1,870
  • 3
  • 22
  • 35
-3
votes
1 answer

I can check if a string is null-terminated but not check it isn't yet null terminated

For the sake of me better understanding C++ strings, array and pointers; I want to know: Why is it that I can use a condition whereby I check if the index has reached the null-terminating character like this... const char* myString =…
K.Roe
  • 33
  • 8
-3
votes
4 answers

Why I can't see that last char in array is null terminator?

How can I check that a char array is null terminated? char input[80]; fgets(input, sizeof(input), stdin); for (i = 0; input[i]; i++) { if (input[i] == '\0') { printf("null!!!"); // never works } } For example, the below code does…
avasin
  • 9,186
  • 18
  • 80
  • 127
-4
votes
1 answer

When does a char* ends with null in c?

I have confusion on char* null-termination so i have decided to make a study of cases i can find. Do these string literals end with a null? char str1[512]="This is a random string" char *str2 = strtok(buffer,"\n,") I have found its answer. This…
Daoist Paul
  • 133
  • 8
-5
votes
3 answers

How is NULL terminated?

Looking to the declaration below const char REASON_POR = "POR"; the question is, why will REASON_POR be NULL terminated ?
user1657666
  • 351
  • 2
  • 9
1 2 3
13
14