Is there any way to change the value of the variable char[] ?
Example:
char a[80]; if (b=d) a="qwerty"; else if (o=f) a="poiuyt"; Is there any way to change the value of the variable char[] ?
Example:
char a[80]; if (b=d) a="qwerty"; else if (o=f) a="poiuyt"; The variable a is an array, and the literal "qwerty" is an array. And it is impossible to appropriate arrays.
Therefore, it is necessary, for example, to make a pointer, i.e. const char* a; ,
or copy arrays with strcpy
char a[80]; if (b == d) strcpy(a, "qwerty"); However, operations with ordinary arrays are fraught with buffer overflows, so it is better to use std::string .
a impossible :) - Harrya is char[80] . - AbyxAll information that interests you here .
UPD
The first way:
char a[50]; strcpy(a, "Hello World!"); The second way:
char a[50]; char b[13] = {"Hello World!"}; for(int i(0);i<13;i++) { a[i] = b[i]; } Source: https://ru.stackoverflow.com/questions/562318/
All Articles
string. - pavel