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
-2
votes
3 answers

what is the relation between these char str[10], char *str and char *str[10] in C?

Can I consider *str[10] as two dimensional array ? If I declare char *str[10]={"ONE","TWO","THREE"} how we can access single character ?
-2
votes
2 answers

How to merge multiple array tokens into one in c

I am trying to merge multiple string array tokens into one, for example: char* args = { "zero" , "one', "two"} Noting that args is not a set size, it could be 1 or 100 I want to make a new array char* array ={"one two"} with the spaces in…
-2
votes
3 answers

How to pass and access C pointer?

How can I make this code work. Address in main is different inside func as well as the value is not the sam ? const char *Like="CO"; void main(){ printf("%d",Like); // o/p 4206935 printf("%c\n\n",(Like[0])); // o/p C func(conLen); } void…
user2636174
-2
votes
1 answer

How do you insert a global variable into the middle of a snprinf statement?

I have a global variable int CYCLE0; I would like to insert into the middle of a very long snprintf statement. snprintf(temp, 400, "\ \ \ ESP32 Demo\ …
brad
  • 870
  • 2
  • 13
  • 38
-2
votes
2 answers

What does this assignment to a string literal do?

This is my code. I want to know what is happening here. Can anybody describe the code? char *string; string = "Le Casa de Papel"; *(str+1) = 'a'; return 0;
asd
  • 51
  • 4
-2
votes
3 answers

Why string reversal function in c code not working?

Code is crash unexpectedly, any logical error in this code? Purpose of this code is to reverse the string. When I try to debug the code, the issue seems in the strrev function. But could not catch up with the exact issue. #include…
Jonson
  • 7
  • 4
-2
votes
2 answers

Why does For-Loop terminate all the codes after itself?

After the for-loop finishes printing myArray, it simply doesn't let any further code to progress anymore and returns the value -1073741819. int main() { char *myArray[]={"Carmaker1","Carmaker2","Carmaker3","Carmaker4","Carmaker5","Carmaker6"}; for…
-2
votes
2 answers

How to append "\" to the start of the string in python

How to append \ character to the start of the string in python, it throws an error saying SyntaxError: EOL while scanning string literal I need to append \ whenever underscore is seen in the string for example: __x_a → \_\_x_a this needs to be…
-2
votes
1 answer

C++: portability of Unicode string literals

While debugging on gcc, I found that the Unicode literal u"万不得已" was represented as u"\007\116\015\116\227\137\362\135". Which makes sense -- 万 is 0x4E07, and 0x4E in octal is 116. Now on Apple LLVM 9.1.0 on an Intel-powered Macbook, I find that…
Mohan
  • 7,302
  • 5
  • 32
  • 55
-2
votes
3 answers

How can I pass an empty string into triple quoted f-string in Python?

Here is a function using a triple quoted f-string with lots of sub-elements: def pass_empty_string(param): from lxml import etree xml = etree.XML(f''' text {param} ... …
Greenev
  • 871
  • 6
  • 23
-2
votes
1 answer

K+R 2.4: bus error when assigning (Mac OS)

I'm currently trying to solve exercise 2.4 of the K+R book and came across an odd error I can't really reproduce elsewhere. I'm using: Apple LLVM version 8.0.0 (clang-800.0.42.1) Target: x86_64-apple-darwin16.4.0 Thread model: posix InstalledDir:…
satou
  • 1
-2
votes
1 answer

How to correctly override literal operators?

Ok, so I made my own class and I've overloaded an operator ""s so I can use it for my string formation. BUT, I get an error when compiling and I have no idea what it means. Could someone explain the meaning of it and how to fix it? my code: PString…
MG lolenstine
  • 919
  • 1
  • 11
  • 32
-2
votes
1 answer

Usage of strcpy with pointers to characters

Why does this code crash? Is strcpy not being used properly?
-2
votes
1 answer

How to put triple qoutes around existing string variable?

Let's say I have this variable: st='MI' and I want to convert it to: st=''' 'MI' ''' to use it in a SQL command. What's the best way to accomplish this? Thanks in advance!
Dance Party2
  • 7,214
  • 17
  • 59
  • 106
-2
votes
1 answer

When we can or cannot modify String Literals

#include int main () { char *s="FIGHT" ; printf("\n Whole string is %s ", s ); // Printing FIGHT -- this is fine s[0]='L' ; printf ("\n Now whole string is %s", s ); // Printing LIGHT -- My Question is how…
theartist33
  • 470
  • 1
  • 6
  • 13