Set char 1 = char 2. What is syntax?

I've been searching for this but found no examples or discussion.

I'm trying to input the value to one char using the value from another, like:
1
2
   char input1[30] = "Input One"; //One of many values
   char subject[30] = input1;  // Push value to Subject 


My subject is a value I'd like to fill dynamically at runtime based on an input response.

My compiler error is: "error: expected '{' before ';' token"
Haven't been able to satisfy it.

Any guidance appreciated.
You can't use the assignment operator= to assign one string to another, you will need to either use C++ strings or strcpy() if you want to stick with horrible C-strings.


You could either overload the = operator or create a small quick function that replaces each char in the first array with the chars from the second one
You can't use the assignment operator= to assign one string to another

You can't use the assignment operator= to assign one plain array to another.
For the language an array is an array, char or not. All arrays fail the same.

A constant C-string literal, like "R2D2" is a shorthand for literal array { 'R', '2', 'D', '2', '\0' }.

You could either overload the = operator

No. Not for plain array. For user types, yes, but there is already "user type" std::string.
create a small quick function

Recreate strcpy() or other C-string handling functions from Standard C Library?
Reinventing a wheel is good for learning, but one should learn to use the existing wheels too.


Note that there is no "operator=" in the OP's code. The = is not that =.
What it is, is part of initialization syntax. Not an operator.
Recreate strcpy() or other C-string handling functions from Standard C Library?
Reinventing a wheel is good for learning, but one should learn to use the existing wheels too.

Oh yes sure, but since strcpy() was mentioned by jlb I didn't emphasize on that further.

My bad on the operator part, thanks for making it clear!
Topic archived. No new replies allowed.