Skip to main content
Filter by
Sorted by
Tagged with
4 votes
3 answers
462 views

From what I understand it is very rare for UTF-8 strings to have embedded NULLs, however there is the case that a person can put a NULL into a Unicode string explicitly with "X\0Y" or ...
Tyler Durden's user avatar
  • 11.6k
0 votes
1 answer
72 views

I don't understand how there is uninitialised variable access in my code and stack buffer overflow even though the two strings are the same when debugging. When i add a null terminator to str2 it also ...
Markus H's user avatar
1 vote
1 answer
176 views

I'm implementing a ziglang function to generate a ulid. So far it works when called via a main function. However, when using it with Bun's FFI it fails. (console.log) is an empty string. Zig const std ...
Mnengwa's user avatar
  • 327
-3 votes
1 answer
218 views

I've copied the entirety of this code: https://learn.microsoft.com/en-us/windows/win32/seccrypto/example-c-program--creating-an-hmac I turned it into a function that accepts two strings. I would like ...
Andrew's user avatar
  • 1,655
4 votes
1 answer
998 views

I tried to add a null terminator (\0) in a string in two ways. One using '\0' and another using "\0", and I'm getting different outputs in both cases: #include <iostream> #include <...
Rahul Kumawat's user avatar
-1 votes
1 answer
295 views

There is a function Foo that takes in an input stream of char. I want to call Foo from my function Bar, which takes in a C-style array with size. char is used to represent a byte (not using std::byte ...
Shuyang's user avatar
  • 518
0 votes
1 answer
1k views

I am new to assembly and i was looking at a hello world program: section .data hello: db 'Hello, World!',10 ; 'Hello, World!' plus a linefeed character helloLen: equ $-hello ...
Konstei's user avatar
  • 59
2 votes
1 answer
415 views

The following C++ source code I compile and run in 'Windows 10' and 'Ubuntu' (via 'WSL 2'): #include <cstring> #include <iostream> int main() { char str[] = "Hello, привет, 😎!&...
Ilya Chalov's user avatar
5 votes
2 answers
3k views

I have a char buffer of known size (for simplicity, let's say a fixed-sized array) from which I would like to construct a std::string. The string in this buffer may be null-terminated or it may run up ...
Parker Coates's user avatar
3 votes
1 answer
270 views

In c '\0' null-terminator as literal takes 4-bytes (as it's just zero internally) but how come it takes only 1-byte when used in an array of characters or string of characters? Is this compiler magic? ...
Mysterious Jack's user avatar
2 votes
1 answer
199 views

I know the string in c will be terminated by a character \0. However, if I do char a[5]="abcd\n" , where would \0 be? Or do I need to reserve at least one position for \0, whenever I try to ...
cy10's user avatar
  • 33
0 votes
1 answer
67 views

I have a character vector like std::vector<char> input({'{', 'a', 'b','}',\0', '{','c','d','}',\0','\0','\0'}); I want to parse this to have strings string1="ab" string2="cd"...
Rajani Bawgi's user avatar
0 votes
2 answers
1k views

I need to read a file into a null terminated string at compile time. Working in Rust OpenGL. I have a shader source code stored in a separate file. The function that will eventually read the source ...
DanielV's user avatar
  • 673
3 votes
2 answers
185 views

Relatively new C programmer here. I am reviewing the following code for a tutorial for a side project I am working on to practice C. The point of the abuf struct is to create a string that can be ...
C-h me's user avatar
  • 103
0 votes
2 answers
89 views

I was solving a challenge on CodeSignal in C. Even though the correct libraries where included, I couldn't use the strrev function in the IDE, so I looked up a similar solution and modified it to work....
generateGeorgina's user avatar
1 vote
1 answer
3k views

In order to implement a client to some protocol that expects null-byte padding to a specific string, I implemented a functions that pads a string with a specific amount of null bytes: string padToFill(...
ring0's user avatar
  • 33
-1 votes
1 answer
52 views

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 <errno.h> #include <fcntl.h> #include <stdio.h> #...
StoneThrow's user avatar
  • 6,435
1 vote
3 answers
2k views

I have seen this coding pattern multiple times when I am reading the source code of different projects. z = read(fd, buf, sizeof(buf)); buf[z] = 0; As far as I know, this is to make sure the c-style ...
heturing's user avatar
  • 352
1 vote
1 answer
1k views

Sometimes I am using sequences of characters (strings) except the null terminator is not needed or wanted, for example if I am using memcpy() and the length is already known. A such, I prefer to omit ...
CPlus's user avatar
  • 5,110
0 votes
0 answers
353 views

I am creating a program to read a list of strings from a text file, and store them in an array (in memory, but formatted like an array of strings). I am on Windows running MIPS on MARS. The text file ...
Jacob's user avatar
  • 301
6 votes
3 answers
6k views

I have a const std::vector<char> - not null-terminated. I want to print it using the fmt library, without making a copy of the vector. I would have hoped that specifying the precision would ...
einpoklum's user avatar
  • 137k
3 votes
1 answer
2k views

How are they different from non-null-terminated strings? What is this null that terminates the string? Is it different from NULL? Should I null-terminate my strings myself, or the compiler will do it ...
n. m. could be an AI's user avatar
0 votes
1 answer
459 views

In c language we can use '\0' null character as end of string. #include <stdio.h> int main() { char msg[] = "hello\0world"; printf("msg = %s", msg); } This code will ...
Naimul Islam's user avatar
-1 votes
1 answer
287 views

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 ...
Ximaz's user avatar
  • 326
0 votes
2 answers
179 views

So in the following code, I want to store each section in the corresponding variable. Is there an easier way to do this rather than looping through the entire string char by char and checking if it's ...
Jorge Jones's user avatar
0 votes
0 answers
285 views

I am studying Assembly language using this nasm tutorial. Here is the code that prints a string: SECTION .data msg db 'Hello!', 0Ah SECTION .text global _start _start: mov ebx, ...
user4035's user avatar
  • 24k
0 votes
0 answers
54 views

string s; In C ++ string is a vector == pointer to start + length. But will there be a closing 0, as implicitly implied by Prat ? class String{ private: char * str; // pointer to string int len; // ...
Влад's user avatar
-4 votes
1 answer
503 views

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 *...
Daoist Paul's user avatar
0 votes
2 answers
375 views

I hava a question.....I have a character array char command[30]. When I use it for input like if I entered !! on console the after input strlength function must give me length of array equals to 2 as ...
Ehtasham Haider's user avatar
0 votes
1 answer
938 views

I know what the null-terminator in C is represented by \0 and has the numerical value of 0. However, when I execute the following code below, the program treats the null terminator as %. I searched ...
Haru Frost's user avatar
0 votes
3 answers
269 views

Looking for a more efficient way to replace leading and trailing empty spaces (' ') and appending an 'X' to the front for each empty space.. It seems to work ok for trailing spaces but I'd like to ...
WannabeEngineer30's user avatar
0 votes
1 answer
123 views

Note: I heavily changed my question to be more specific, but I will keep the old question at end of the post, in case it is useful to anyone. New Question I am developing an embedded application which ...
Spyros Mourelatos's user avatar
2 votes
1 answer
276 views

I can define a new variable like so msg db 'Hello, world!$', or another way msg2 db 'Hello, world!', 0 I know that the end of a string is determined using value 0 in memory. What is symbol $ standing ...
alexander.sivak's user avatar
3 votes
2 answers
5k views

Say for instance I declare a char array with all values set to zero in the following fashion: char array[4] = {0}; If I assign it values, for instance: array[0] = 'A'; array[1] = 'B'; array[2] = 'C'; ...
asd23553's user avatar
1 vote
1 answer
513 views

So, I have a class class MySuperClass { public: std::string buffer; }; And wants to print buffer to std::cout. Here's some code about filling string from a file: MySuperClass msc; std::fstream file(&...
shArky's user avatar
  • 35
0 votes
0 answers
735 views

I am wondering how can I properly null-terminate a string in assembly language: what I did was simply setting movq $0, (position_to_terminate) and I thought this will terminate my string. However, ...
M. Chen's user avatar
  • 213
0 votes
2 answers
3k views

It is clearly written for strcat, e.g. here and here that, in case, char *strcat(char *s1, const char *s2); then, The initial character of s2 overwrites the null character at the end of s1. But ...
Duck Dodgers's user avatar
  • 3,481
3 votes
2 answers
2k views

So I am creating a char to string converter and I am creating a string using malloc. I know I need to make space for the null terminating character \0. So do I do char *example = malloc(sizeof(char) + ...
user avatar
0 votes
1 answer
554 views

I've tried to write an implementation of the Weasel Program. I have compiled three versions, all exactly identical, with the names "weasel.exe", "weasel2.exe", and "weasel3....
TwistyTurtleFish's user avatar
0 votes
1 answer
229 views

I want to use strtok and then return the string after the null terminator that strtok has placed. char *foo(char *bar) { strtok(bar, " "); return after_strtok_null(bar); } /* examples: foo(&...
avivgood2's user avatar
  • 247
0 votes
0 answers
59 views

I was searching if Java strings are null-terminated like in C and came across the first answer for this:Does java define string as null terminated? Basically the link mentions that the length method ...
Leon's user avatar
  • 362
1 vote
2 answers
571 views

I'm learning C via "The C Programming Language" book. During one of the exercises, where it's needed to concatenate two strings, I found that there are two null terminating signs (\0) at the end of a ...
SGKz's user avatar
  • 13
3 votes
3 answers
416 views

I need to use array of graph data, i.e. struct with x and y integers. This array will be passed through many functions, and I need to decide the API choice. typedef struct { int x; int y; } ...
Tuppe's user avatar
  • 63
2 votes
3 answers
463 views

I have a vector of type UInt8 and fixed length 10. I think it contains a null-terminated string but when I do String(v) it shows the string + all of the zeros of the rest of the vector. v = zeros(...
dantheman's user avatar
  • 171
2 votes
1 answer
260 views

String::String(const String& old_str) { size = old_str.size; s = new char[size+1]; Why do we use size+1 here to allocate memory, not size?
Bond's user avatar
  • 25
11 votes
3 answers
318 views

I am supposed to answer a homework question for one of my classes. Specifically, I am supposed to say if certain arrays in C are considered strings or not. Based on this article (https://www....
quango's user avatar
  • 137
4 votes
2 answers
7k views

The title almost says it all. void f(const char*) to void f(std::string_view) Is it safe? if not, what are the pitfalls? std::string_view semantics dictate that the array isn't necessarily null ...
darune's user avatar
  • 11.5k
0 votes
3 answers
119 views

The following code works as expected and outputs ABC: #include <stdio.h> void printString (char toPrint [100]); int main() { char hello [100]; hello[0] = 'A'; hello[1] = 'B'; hello[2] ...
gnidoc's user avatar
  • 47
4 votes
3 answers
3k views

I have the following code. #include <stdio.h> #include <string.h> #define MAXLINE 1000 int main() { int i; char s[MAXLINE]; for (i = 0; i < 20; ++i) { s[i] = i + ...
ljosja_'s user avatar
  • 91
-1 votes
2 answers
721 views

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. *****************************************...
JDS's user avatar
  • 1

1
2 3 4 5