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

When String object is created by concatenation of string literal variable and String?

public class SubString1 { public static void main(String[] args) { String s="Sachin"; String sb=s+"Tendulkar"; String sbc="SachinTendulkar"; System.out.println(sb==sbc); } } Output : false. Please Explain how the output is false?? I couldn't…
-2
votes
2 answers

SyntaxError: unterminated string literal error in javascript

while passing string parameters from java to javascript function it breaks if parameters contains space in it. String str = "This is test"; sb.append("test"); then while clicking on this hyper link…
user3340357
  • 101
  • 1
  • 2
  • 6
-2
votes
2 answers

C char array implementation

I'm trying to take user input using the getline() function. I store the input and point to it with a char *pointer. Now I want to split the string at the white space, if there is any, but I can't change a string literal. So my idea was to transfer…
Ryan H
  • 85
  • 4
  • 13
-2
votes
3 answers

Why C program crashes?

Please, someone explain why the following C program crashes: void changeChar(char *string); int main(int argc, char *argv[]) { char *test = "word"; changeChar(test); return 0; } void changeChar(char *string) { *string = 'A'; } while the…
-3
votes
2 answers

== doesn't works when comparing argv[] strings

I noticed that comparing a normal string variable with a string using strcmp and == operator both works, but comparing argv string using == doesn't works, only it works with strcmp. why? What is so special? #include #include…
-3
votes
3 answers

C2664 'cMan::cMan(char *,char *,double,int)': cannot convert argument 1 from 'const char [6]' to 'char *'

Hello I am just learning C++. I have this code but when I try to build the solution error from title shows up. Any ideas how to fix that? class cMan { public: cMan(char *chFirstName, char *chLastName, double dWeight, int iHeight); ~cMan(); …
-3
votes
1 answer

I can't trace this pointer to pointer array program

#include using namespace std; char* str[]={"Man","Woman","Car","Plane",0}; int main(){ char** cp=str; while(*cp!=0) cout<<*cp++<
-3
votes
3 answers

having a problem with conditional operator in c

I am trying to make a program to determine if the entered number is positive or negative with the conditional operator but when I enter the number the program doesn't print anything after #include void main(void) { char number; …
-3
votes
2 answers

How to fix an issue with shaders?

I'm working on writing code for simpliest shader. Here is its code. const char* Vertex_Shader_Descrip = "#version 330/n" "layout(location = 0) in vec3 position;/n" "void main()/n" "{/n" "gl_Position = vec4(position.x, position.y, position.z,…
-3
votes
6 answers

Why printf prints a variable not passed as argument?

I didn't write C code for a long time, I'm rusty. Anybody knows why the following code prints "rtyaze" to stdout ? I was expecting "rty". #include int main (void) { char s[] = "aze"; char ss[][3] = { "rty" }; printf("%s\n",…
user1636522
-3
votes
3 answers

C - string concatenation with pointers

why does the following string concatenation does not work? main() { char *str1 = "United"; char *str2= "Front"; char *str3; str3 = strcat(str1, str2 ) ; printf("\n%s",str3 ); } I got this problem in exercise questions in one of a book on pointers.…
-3
votes
1 answer

Python 3.6 literal strings

I'm having a hard time finding what can be put inside literal strings. For example, I've seen this code on the PEP above, yet I didn't find any information above about what it does. >>> value = 1234 >>> f'input={value:#06x}' 'input=0x04d2' Is there…
Yuval Meshorer
  • 156
  • 2
  • 8
-3
votes
1 answer

Any way to use string literal u8 with a variable?

Any way to use u8 literal with a varible? const char* name[32]; (u8)name//something like this I need to convert name to utf-8 and i just don't know how.
SLI
  • 713
  • 11
  • 29
-3
votes
4 answers

Can a string literal and a non-string non-compound literal be modified?

String literals are lvalues, which leaves the door open to modify string literals. From C in a Nutshell: In C source code, a literal is a token that denotes a fixed value, which may be an integer, a floating-point number, a character, or a …
Tim
  • 1
  • 141
  • 372
  • 590
-3
votes
2 answers

Is there a way to split a literal string to multiple lines with out enter to it \r

In my code i got a very long and complicated string that I want to save as a literal string At the moment my line is 1200 character long. And I want to separate the lines in the way which every line it wouldn't be longer than 200 characters string…
Rafa_G
  • 45
  • 1
  • 10