Questions tagged [string-literals]

String literals concern the syntactic representation of literal constant strings in C, C++ and others.

C and C++ have several ways to represent strings in code. They include the basic double quoted "Hello, World!". Strings can be concatenated "as" " follows". C++-0X has added new encodings u"Hello" for UTF16 (char16_t), U"world" for UTF32 (char32_t) is addition to L"long" for wchar_t. There are rules for concatenating different encodings.

1193 questions
-1
votes
2 answers

How to print to the return value of a function, using format modifiers, in C?

Don't know if this is possible. I've been searching for it but nothing comes up. I'd like to have a function that merges multiple values and returns them as a string literal (so no malloc and subsequent free). This could be achieved by printing to…
Daniel
  • 2,380
  • 29
  • 44
-1
votes
5 answers

Error returning char* in c++ function

I have this function: char* return_string(){ char buffer[] = "Hi world!"; return buffer; } bool test08() { char compare[] = "Hi world!"; int result = strcmp(compare,return_string()); if (result == 0) return true; return false; } int…
IBot
  • 356
  • 3
  • 20
-1
votes
1 answer

replace single backslash in database driven string

This might seem like a question that's been answered many times. My team and I have tried many solutions over the past hour without any luck. We have a database driven string value that contains c:\test and we want to replace the backslash with \\…
CubeRoot
  • 552
  • 2
  • 13
-1
votes
2 answers

c - Why do they all point to the same place?

Why do they all point to the same place? It is an optimization? #include #include #include #include #include const char* func1(const char str[]){ // printf("%p\n", str); return str; } const…
sapitando
  • 59
  • 4
-1
votes
2 answers

Html helper within an html helper (rendering razor correctly from string literal)

I made a custom HTML helper for the contact modal so that anyone on our app can use it with @Html.ContactModal(model and options go here), but the issue is that on the modal there's another html helper for the sales code drop down, and the razor…
ranah
  • 707
  • 1
  • 6
  • 11
-1
votes
3 answers

Example when two strings compared by == and equals() will give different results?

When is a == b is true but a.equals(b) is false, or vice versa? I know that equals() is used to compare the values of the Strings and the == to check if two variables point at the same instance of a String object. But in which case will these two be…
MagicBeans
  • 343
  • 1
  • 5
  • 18
-1
votes
2 answers

Index operator bound to a string literal

So I decided to experiment, completely out of randomness. And I found this: "Hello World"[1] Actually working on a first view, resulting in 'e' even though: I haven't encounter this anywhere until happened to be in my code Seems semantically…
Imobilis
  • 1,475
  • 8
  • 29
-1
votes
1 answer

Unexpected C string definition behaviour

As far as I know the below code should not work. Yet, somehow this is OK on my compiler. Please could someone explain. int main() { char *string; string = "Goo"; }
-1
votes
1 answer

Unwanted slash in string literal

I'm trying to pass a filename to a cmd prompt. Ive looked various places but cant seem to find the answer - I'm sure its simple. My string is built like so: string cmd = string.Format(@" -u{0} -p{1} -h{2} -P{3} {4} < ""{5}""", user,…
Simon
  • 9,197
  • 13
  • 72
  • 115
-1
votes
3 answers

What is wrong with my strings?

The following code is generating an error and I cannot see the issue. Can anyone help? customer_array = [‘Ken’,’William’,’Catherine’,’Mark’,’Steve’,’Sam’] customer_hash = { ‘Ken’ => ‘Fiction’, ‘William’ => ‘Mystery’, ‘Catherine’ =>…
Ninja2k
  • 819
  • 3
  • 9
  • 34
-2
votes
1 answer

Learning JavaScript Basics

Help me correct "Escaping Literal Quotes in Strings" click this for the code>> https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/escaping-literal-quotes-in-strings I am just trying this on free code camp…
Newton5000
  • 21
  • 4
-2
votes
3 answers

How does this overloading of square brackets work

I want to avoid printing space (" ") or an underscore ("_") after the last element of an array while printing them using a for loop. The problem mentions one of the way to do so, I want to understand how and why this happens. vector v1 =…
-2
votes
3 answers

String not assignable to char array in C

Hello I am very new to C and I have a simple question. Why does the second method of assigning a string to char name2[] not work? It causes a compilation error saying "Array type 'char[20]' is not assignable". int main() { char name[20] =…
zach
  • 37
  • 6
-2
votes
2 answers

Can't copy a string to a pointer

Hi I'm pretty new to C and still don't have a full understanding of pointers, but essentially I'm trying to copy the result of my encryption to the result pointer, and it keeps throwing various errors, currently a segmentation fault. As far as I…
-2
votes
2 answers

Convert string to raw string

char str[] = "C:\Windows\system32" auto raw_string = convert_to_raw(str); std::cout << raw_string; Desired output: C:\Windows\system32 Is it possible? I am not a big fan of cluttering my path strings with extra backslash. Nor do I like an…
user3600124
  • 829
  • 1
  • 7
  • 19