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
0
votes
3 answers

C print whole string variable (ignore \0 termination)

An example says more than thousand words: unsigned char *hello = (unsigned char*)malloc(STR_LEN * sizeof(unsigned char)); const char *str= "haha"; memcpy(hello, str, strlen(str) + 1); How can I print the content of the whole hello-variable…
NaN
  • 3,501
  • 8
  • 44
  • 77
0
votes
1 answer

NULL terminator on string included via AS's incbin directive

I have some large string resources located in files that I include in my executable. I include them in the executable using the following. The *.S allows GCC to invoke as to produce the object file without any special processing. ;; ca_conf.S …
jww
  • 97,681
  • 90
  • 411
  • 885
0
votes
5 answers

NULL terminated c_str()?

Why does using is_it_valid_color("yellow") work and outputs FOUND IT but using is_it_valid_color(x.c_str()); not work? I have a feeling it has to do with null terminated strings. The output looks the same in console: color: 'yellow' FOUND IT color:…
ParoX
  • 5,685
  • 23
  • 81
  • 152
0
votes
3 answers

how to terminate a string in c++

#include #include #include using namespace std; int main() { string a; cin>>a; int len=a.length(); bool hit[256]; memset(hit,0,sizeof(hit)); hit[a[0]]=1; int tail=1; for(int i=1;i
user2416871
  • 543
  • 1
  • 4
  • 13
0
votes
2 answers

Representation of C string at memory and comparison

I have such code: char str1[100] = "Hel0lo"; char *p; for (p = str1; *p != 0; p++) { cout << *p << endl; /* skip along till the end */ } and there are some parts not clear for me. I understand that null-terminated string at memory is byte…
Viacheslav Kondratiuk
  • 8,493
  • 9
  • 49
  • 81
0
votes
2 answers

Mental block on fprintf string termination

I am at a total loss with this one. I can't figure out why this isn't working. Simple character array with a NULL terminator - except that when I output it, it doesn't terminate! int file_create(const char *path) { //trying to trap situations…
AndroidDev
  • 20,466
  • 42
  • 148
  • 239
0
votes
5 answers

A C style string file format conundrum

I'm very confused with this wee little problem I have. I have a non-indexed file format header. (more specifically the ID3 header) Now, this header stores a string or rather three bytes for conformation that the data is actually an ID3 tag (TAG is…
aviraldg
  • 9,531
  • 6
  • 41
  • 56
-1
votes
1 answer

fprintf on (unterminated?) C-string doesn't spew garbage or segfault -- undefined behavior?

I recently learned (initially from here) how to use mmap to quickly read a file in C, as in this example code: // main.c #include #include #include #include #include #include…
StoneThrow
  • 5,314
  • 4
  • 44
  • 86
-1
votes
1 answer

Non null-terminated string reading standard input (Assembly Language)

I'm working on making a standard library from scratch in assembly language using NASM. I'm not doing this to use it in huge project, but just to train myself with assembly language making a project that I can put on GitHub. Anyway, I'm facing…
Ximaz
  • 198
  • 2
  • 9
-1
votes
2 answers

Char pointer NULL termination and memory allocation

I have the following program : My program compiles fine and gives the output as mentioned below . I have some question on output which is listed at the bottom. *******************************************************************************/ #include…
JDS
  • 1
-1
votes
3 answers

Copy a string into another without \0

I have to put a string into another without \0, I tryed a lot of ways but the string is always dirty. char string[100]; int pos=0; fgets(string, 99, stdin); len = strlen(string); printf("%d\n", len); char array[len-1]; for(pos=0; pos<(len-1);…
Nina06
  • 3
  • 3
-1
votes
1 answer

Splitting string in C by null terminator

I am currently trying to implement a program that intakes a file, reads the file and copies its contents to an array (farray). After this we copy the contents of farray as strings separated by null terminators into a string array called sarray. For…
s.gang
  • 131
  • 3
  • 14
-1
votes
2 answers

null terminated character is not recognized

I use the OPENFILENAME ofn way to open a browse file dialog in win32 application. I want to be able to use dynamic the file filtering according to what user needs and not as predefined to all files ofn.lpstrFilter = L"All Files\0*.*\0\0"; I tried…
Nocs
  • 71
  • 10
-1
votes
2 answers

Assigning NULL to the middle of a c-string

I'm writing a function eliminate(char *str, int character) that takes a c-string and a character to eliminate as input, scans str for instances of character and replaces the value at the current index with... what? I thought NULL, but this seems…
Mike B
  • 125
  • 1
  • 1
  • 10
-1
votes
1 answer

A bunch of questions about C++'s cstring

I have a few questions I would like to clarify about cstrings: 1) Initialization: When declaring an array of characters as follows, does C++ automatically defines it as a cstring? or (as I believe) an array of characters? char a[10]; In other words,…
Gil Dekel
  • 355
  • 4
  • 15
1 2 3
13
14