c-strings Questions
20
Solved
The following code receives seg fault on line 2:
char *str = "string";
str[0] = 'z'; // could be also written as *str = 'z'
printf("%s\n", str);
While this works perfectly well:
char str[] = "s...
Parallelogram asked 2/10, 2008 at 19:45
5
Solved
I have a string to convert, string = "apple" and want to put that into a C string of this style, char *c, that holds {a, p, p, l, e, '\0'}. Which predefined method should I be using?
6
Solved
I want to select the first 8 characters of a string using C++. Right now I create a temporary string which is 8 characters long, and fill it with the first 8 characters of another string.
However,...
11
Okay so I'm trying to make a program which allows user to input their email. Their email will be considered valid if two stipulations are met: A. there must be an "@" sign somewhere in there and B....
Bolinger asked 28/4, 2016 at 2:2
3
Solved
I think i quite understand how to use the keyword constexpr for simple variable types, but i'm confused when it comes to pointers to values.
I would like to declare a constexpr C string literal, w...
Nikolenikoletta asked 7/9, 2017 at 15:36
2
Solved
It is not immediately clear from the standard what strncmp (from string.h)
int strncmp(const char *s1, const char *s2, size_t n);
should return if its 3rd argument n is 0.
According to the C17 sta...
Peraza asked 3/4, 2023 at 13:36
1
Solved
The following code prints 1010
#include <iostream>
#include <range/v3/algorithm/starts_with.hpp>
int main () {
using namespace std::literals;
std::cout << ranges::starts_with(&...
8
Solved
I'm trying to convert (and round) a double to a char array without converting with a std::to_string on the double first. However, I'm receiving random memory text instead. What am I doing wrong?
...
7
Solved
I've seen some posters stating that strdup is evil. Is there a consensus on this? I've used it without any guilty feelings and can see no reason why it is worse than using malloc/memcpy.
The only...
7
Ok, so I'm a person who usually writes Java/C++, and I've just started getting into writing C. I'm currently writing a lexical analyser, and I can't stand how strings work in C, since I can't perfo...
Stralka asked 15/7, 2014 at 3:45
6
Solved
I just discovered very weird behavior from the C compiler. It's very simple code. I tried it in many online C compilers, but the result is always the same, which is driving me insane.
#includ...
Jehoash asked 4/9, 2022 at 23:3
4
Solved
When terminating a string, it seems to me that logically char c=0 is equivalent to char c='\0', since the "null" (ASCII 0) byte is 0, but usually people tend to do '\0' instead. Is this purely out ...
Coypu asked 6/6, 2013 at 7:16
5
Solved
I have a C-program (an Apache module, i.e. the program runs often), which is going to write() a 0-terminated string over a socket, so I need to know its length.
The string is #defined as:
#define...
Aideaidedecamp asked 23/10, 2010 at 9:56
4
Solved
I am writing a very simple program that removes duplicate chars from a string. I ran it visual studio and got the error:
Unhandled exception at 0x00d110d9 in inteviews.exe: 0xC0000005: Access vi...
3
Solved
How do I set this up to only read the first word the user enters IF they enter to much info?
I do not want to use an if-else statement demanding they enter new info because their info was to much...
4
Solved
I am not a C programmer, so I am not that familiar with C-string, but now I have to use a C library, so here is a shortened version of my code to demonstrate my problem:
char** ReadLineImpl::my_com...
2
Solved
In C++, I'm trying to print the address of a C-string but there seems to be some problem with my cast. I copied the code from a book but it just doesn't compile on my mac.
const char *const word =...
3
Solved
I need a help on one question where I stuck while coding my app in MFC.
I am using CLR i.e Common Language Runtime in my application to integrate c# APIs.
but now I stuck on converting System::Str...
6
Solved
I wrote this small piece of code in C to test memcmp() strncmp() strcmp() functions in C.
Here is the code that I wrote:
#include <stdio.h>
#include <stdlib.h>
#include <string.h&g...
16
Solved
CString is quite handy, while std::string is more compatible with STL container. I am using hash_map. However, hash_map does not support CStrings as keys, so I want to convert the CString into a st...
2
Copy a substring from main string using CString library functions.
CString FilterCriteria ="MESSAGE=2 AND READ = 2 AND Instance=\'SMS/MMS\'
AND Folder=\'inbox\'";
CString o_filter;
Now, i want ...
3
Solved
How to create a null-terminated string in Go?
What I'm currently trying is a:="golang\0" but it is showing compilation error:
non-octal character in escape sequence: "
4
Solved
So I'm trying to replace cc with & in a sentence (eg: "Hi this is Mark cc Alice"). So far I have this code where it replaces the first c with & but the second c is still there. Ho...
8
Solved
9
Solved
I am trying to find if there is better way to check if the string has special characters. In my case, anything other than alphanumeric and a '_' is considered a special character. Currently, I have...
1 Next >
© 2022 - 2024 — McMap. All rights reserved.