2,793 questions
4
votes
3
answers
138
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
136
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
141
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
107
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
166
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 ...
1
vote
2
answers
62
views
Line extraction in a char
Hi i'm trying to write a recursive function to extract each line of a string. I don't know why it doesn't work i spent 2 hours trying to find the issue.
#include <string.h>
#include <stdlib.h&...
1
vote
2
answers
99
views
How to debug this substring matching code?
I am a beginner in C programming, and this is a string matching code I wrote. It aims to find the positions where the substring t appears in the string s and print them. The use of pointers is ...
0
votes
0
answers
8
views
CString formatting from hexadecimal array causing segmentation fault on Raspberry Pi
Trying to convert a hexadecimal unsigned char array into a CString and printing:
unsigned char hexArray[] = { 0x1A, 0x2B, 0x3C, 0x4D, 0x5E, 0x6F };
CString strArray;
strArray.Format(_T("%02x-02x-...
1
vote
3
answers
86
views
c++ manual concatenation of c-strings function that is called twice and adds a space
I have an assignment to write a function that takes two C-string parameters and appends the second to the first just like the strcat function but without using said function. Then, write a main driver ...
0
votes
1
answer
52
views
During the second call of strtok(), the code raises the following error: Invalid read of size 1
I am new to C++ and I do not understand why the code doesn't continute tokenizing the text array, and instead raises the error.
I suspect that the problme might be because of passing the token ptr mid-...
0
votes
0
answers
26
views
Does cstring variables needs to be static to work with ESP8266?
Despite 5 years of development with ESP8266 (mini D1) I'l still confused:
My IDE version is 1.8.19
My sketch is 3300 lines but I made a test case:
This is the sketch:
// Globals
int i=1;
void setup() ...
4
votes
2
answers
167
views
Why does fgets() require a maximum size of user input? Is it because it does not have the "restrict to first space" property of scanf()?
This is fgets()'s official prototype:
char *fgets(char *str, int n, FILE *stream);
Why specify the size (n) ? Is it to prevent buffer overflow of some sort? Or is it just a design flaw?
I would think ...
1
vote
3
answers
138
views
How to store a dynamic C string
For an assignment in my college data structures class, we have to define functions for a palindrome class that takes a word, checks if it is a palindrome, stores it as half the word, and can access ...
1
vote
1
answer
83
views
How to compare an array with a char using if in C?
I ask for your help. I need to compare an array of tokens with a char using the if statement. But in the array I also have a string, the code is this:
char bho(char** Token){
char* token = (char*)...