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?
Files asked 6/8, 2012 at 1:8

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,...
Millimicron asked 4/12, 2015 at 20:41

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(&...
Marksman asked 22/3, 2023 at 22:47

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? ...
Griqua asked 6/6, 2018 at 0:12

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...
Thromboplastin asked 20/10, 2012 at 3:18

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...
Catena asked 10/12, 2011 at 18:56

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...
Medeah asked 2/2, 2017 at 1:15

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...
Volute asked 4/8, 2013 at 8:23

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 =...
Brancusi asked 12/5, 2015 at 21:18

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...
Averil asked 11/1, 2014 at 7:47

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...
Trunk asked 26/10, 2012 at 22:57

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...
Phelgon asked 3/11, 2008 at 6:58

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 ...
Hulsey asked 11/8, 2017 at 13:24

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: "
Perice asked 24/6, 2016 at 6:57

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...
Lethbridge asked 15/11, 2020 at 3:12

8

Solved

I tried to implement strcmp: int strCmp(char string1[], char string2[]) { int i = 0, flag = 0; while (flag == 0) { if (string1[i] > string2[i]) { flag = 1; } else if (string1[i] < stri...
Constabulary asked 19/1, 2016 at 9:38

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...
Etruria asked 7/7, 2011 at 2:46

© 2022 - 2024 — McMap. All rights reserved.