This is linked to my previous post
Wher I created a Struct :
struct buffer
{
char ProjectName[20];
char ProjectID[20];
};
Now while I am trying to assign values to it:
buffer buf;
buf.ProjectID = "3174";
buf.ProjectName = "NDS";
I am getting this error:
error C2440: '=' : cannot convert from 'char [5]' to 'char [20]'
and to resolve this I tried decreasing the size of structure as below(must not be the way to do it) :
struct buffer
{
char ProjectName[4];
char ProjectID[5];
};
and the get error C2106: '=' : left operand must be l-value
You have to copy the string into the array:
strcpy(buf.ProjectName, "3174");
Be careful with the length of the strings being copied into the arrays
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With