3,290 questions
3
votes
2
answers
259
views
Why does "\0" give integer in c
So, I am learning C language and was trying to make a function that returns the length of a string. In the if statement I mistakenly used "" instead of ''. So, instead of comparing to char '\...
2
votes
2
answers
122
views
Why does my function replace my letters with weird characters? [closed]
My goal is to recreate the strcat() function without libraries:
#include <stdio.h>
char *ft_strcat(char *dest, char *src)
{
int i;
int j;
i = 0;
j = 0;
while (dest[i] !...
1
vote
3
answers
140
views
Inputting to a cstring of undefined size without wasting memory [closed]
I know beginner level C++. In C++ when I want to, for example. input the user's name, all I need to dos is:
getline(cin,str);
but I am trying to learn C.( I want to play with kernels and embedded ...
3
votes
2
answers
150
views
Is it safe to call free on std::string_view::data?
Is it safe to call free in the example below:
size_t len = 10;
char* buffer = static_cast<char*>(malloc(len));
std::string_view sview(buffer, len);
free(sview.data())
Why do I need this?
I have ...
0
votes
3
answers
188
views
What is a null operation?
I have a question related to null operation in C. From my understanding and the thing i read here, a null operation or differently called a null byte, is used to tell the compilers the end of the ...
0
votes
0
answers
36
views
Issues With Pointers and Memory While Making C-String Functions From Scratch in C++
I need help looking for the source of an error that's plaguing me in my coding assignment (I'm doing the class online over the summer.). The professor is tasking the class with several cstring ...
0
votes
3
answers
125
views
Line 17: Char 20: runtime error: left shift of 1 by 31 places cannot be represented in type 'int' [solution.c] [closed]
bool isSubsequence(char* s, char* t) {
int len = 0;
bool res = false;
int k = 0;
len = strlen(t);
char str[len+1];
uint64_t z;
for (uint64_t i = 0; i < pow(2, len)...
2
votes
3
answers
143
views
Can someone help me understand this unexplained behaviour in C char arrays?
I have a function called escape that copies over a character array into a new one while replacing the \t and \n characters with raw characters \t and \n i.e single character '\n' becomes 2 characters '...
4
votes
2
answers
122
views
how to change color in a string in c?
My problem is that I have a string which is colored gray, the string is almost 1000 characters long. 2 of them must be in another color (red), but I don’t know how to change the color in the string.
...
3
votes
3
answers
155
views
remove a character by using conditional statement
recently just practiced the problem 67 in Leetcode This problem is like you would be given two binary string, and you have to calculate the sum of these two binary string and return the result.For ...
10
votes
2
answers
1k
views
Are the literals "" (empty string) and "\0" (null string) identical? [duplicate]
Is there any situation where the literal const char*s "" and "\0" differ, or are they identical?
Edit: As requested that an edit should be added, the answer to this question was ...
-1
votes
1
answer
167
views
How to reduce memory used by an array buffer? [closed]
I am learning C++. I have a code which is working, but now I am wondering if it can be optimized in terms of memory usage?
I need to get and keep a few strings in a character array, but the number of ...
4
votes
3
answers
369
views
If I am using UTF-8 strings is it risky to use standard string handling that assumes null termination?
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 ...
2
votes
1
answer
240
views
How to convert cString into String in Swift6?
The following code produces a warning in Swift6:
'init(cString:)' is deprecated: Use String(decoding: array, as:
UTF8.self) instead, after truncating the null termination.
var size = 0
...
3
votes
4
answers
172
views
Change pointer adress inside function in C
I'm trying to make a program that deletes extra white spaces from a string. It should keep one space but delete any extra.
I wrote this code, which works up until the point I have to change the passed ...