How do I paste a const/literal string?

Asked 2 years ago, Updated 2 years ago, 77 views

message = strcat("TEXT " , var);

message2 = strcat(strcat("TEXT ", foo), strcat(" TEXT ", bar));

I'm trying to put a string after a fixed string It keeps saying Segmentation Fault.

How do I paste a const/literal string?

string c concatenation

2022-09-22 11:11

1 Answers

message = strcat("TEXT " , var);

Is the intention to do ("TEXT" + var) and save the address in the message?

char * strcat (char * destination, const charge * source); and destination must be char array buffer.

But a string like "TEXT" cannot be expressed properly in Korean.It's a kind of constant because it's ), so you can't put another string after it.

To code with this intention

char myTEXT[] = "TEXT ";
message = strcat(myTEXT, var);

In the same way, "TEXT" should be stored in a separate writable memory space.


2022-09-22 11:11

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.