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
1 answer

string printed in reverse without reversing in the code

I tried to print the string by declaring it via ternary operator. Instead of any error it prints string in reverse. Can someone explain please? I was expecting string to be printed as even or odd based on the input. #include void…
-1
votes
1 answer

Return const char** from immutable string

I want to set return a const char* into char** I want the compiler to validate there is no change on that char*. What the correct syntax should look like? const char* str = "some str"; void test(char const **out_str) { *out_str = str; } EDIT:…
igor
  • 716
  • 1
  • 9
  • 27
-1
votes
1 answer

Adding strings and literals, how does the order affect if you can add the strings without error

Consider the following string definitions: string s1 = "hello", s2 = "world"; string s6 = s1 + ", " + "world"; string s7 = "hello" + ", " + s2; The book C++ Primer 5e states that the third line will cause the compiler to give an error because you…
Jinzu
  • 1,325
  • 2
  • 10
  • 22
-1
votes
1 answer

How to assign an array of characters to a string literal

I have an array of char and I'm trying to have a string literal with the same chars in the array. I tried strcpy, and try =, and I tried what I did in the following code. But it doesn't seem to work or I'm understanding something. char…
-1
votes
1 answer

How can you keep escape characters when appending a string to a StringBuilder object?

I am trying to add a user input string to a StringBuilder I can then use elsewhere to display the string I'm building. The problem is when a user does a carriage return and I try to append that to the StringBuilder it removes the escape characters…
Sentius
  • 7
  • 6
-1
votes
1 answer

How to compare the output of crypt() to a cmd line input for cracking passwords in C

I'm taking the cs50x intro to comp sci course and one of the exercises is to decrypt a password that was encrypted using the crypt(3) function. They've simplified the requirements by setting the hypothetical that the password can only be 5…
Roznoshchik
  • 95
  • 1
  • 9
-1
votes
2 answers

Do I risk a buffer overrun here and how would I avoid it?

I implemented an easy list structure where single list elements are defined by the following structure: struct list_elem { struct list_elem *next; // ptr to the next element char *data; // ptr to data }; Now, I want to do the…
Lavair
  • 888
  • 10
  • 21
-1
votes
1 answer

Raw string literal in Constant block

I am testing the x509 Certificate Verify example, and this (from the example) works: const rootPEM = ` -----BEGIN CERTIFICATE----- MIIEBDCCAuygAwIBAgIDAjppMA0GCSqGSIb3DQEBBQUAMEIxCzAJBgNVBAYTAlVT . . . yuGnBXj8ytqU0CwIPX4WecigUCAkVDNx -----END…
sean
  • 3,484
  • 5
  • 27
  • 45
-1
votes
1 answer

JavaScript: convert string literal to string

I want to convert string literals to strings. For example: var stringLiteral="\\\" hi world \\\""; console.log(stringLiteral) //outputs \" hi world \"; var string=convertStringLiteralToString(stringLiteral); // ^ eval() would be perfect for this…
Ben Rivers
  • 129
  • 10
-1
votes
4 answers

Does the C equality operator compare the literal value of two strings or their memory locations?

I cannot understand this behaviour of the == operator: char s1[4]; s1[0] = 'a'; s1[1] = 'a'; s1[2] = 'a'; s1[3] = '\0'; char *s2 = "aaa"; char *s3 = "aaa"; printf("s1: %s\n", s1); // aaa printf("s2: %s\n", s2); // aaa printf("s3: %s\n", s3); //…
nourdine
  • 7,407
  • 10
  • 46
  • 58
-1
votes
1 answer

Debugging: SQL inside Python Psycopg2

sql = "WITH users AS(SELECT * FROM stats.core_users cu LEFT JOIN XXXX.sent_hidden_users h USING(user_id)\ WHERE cu.status = 'hidden' AND h.user_id is null AND cu.country_code = 86 LIMIT 100)\ SELECT\ cu.user_id,\ CASE WHEN cu.gender =…
Qiao Zhang
  • 569
  • 4
  • 9
-1
votes
2 answers

How does "str" - "str" in C work? How are they stored?

Disclaimer: This question asks how "str literal" + "str literal" works For how 'a' + 'b' or '9' - '0' = 9 ('character' + 'character') works : Why does subtracting '0' in C result in the number that the char is representing? C character values…
cdpp
  • 152
  • 2
  • 9
-1
votes
1 answer

Replacing character within string

This is a very basic question, it has been asked alot, but all of the examples I have looked at have been slightly different #include int main() { char title[] = "HELLO!"; title[1] = "F"; printf("%s", title); } Why does…
eZ_Harry
  • 816
  • 9
  • 25
-1
votes
1 answer

Convert python string representation with '\n' to real python list

This code gives me an error message - obviously because of the \n in the string-list. Error Message: SyntaxError: EOL while scanning string literal import ast string = "['Text1', 'Long text\nwith new…
KatharsisHerbie
  • 115
  • 1
  • 10
-1
votes
1 answer

When are string literals allocated

When are string literals allocated and put into the string pool? Specifically, if a string literal is never reachable by any code path, will it ever be allocated? Imagine you have the following code fragment: …
Svetlin Zarev
  • 14,713
  • 4
  • 53
  • 82