+ 1

How to Assign Char variable value of one structure array to another?( C++)

I have 2 structure Struct ItemInfo{ Char itemName[50]; }; Struct BillInfo{ Char BitemName[50]; }; When I try to initialize Billinfo.BitemName = iteminfo.itemName; Error occur that "Expression must be modifiable Lvalue" If I put asterisk at the beginning of both variables at the time of initialization it work but it store garbage value... Can anyone help me please

30th Jan 2020, 4:49 PM
Faisal Ur Rehman
Faisal Ur Rehman - avatar
4 ответов
+ 2
This doesn't answer your question, but if you are using C++ you should use the string library and use string instead of char*. They provide more functionality and can use the assignment operator on eachother.
30th Jan 2020, 5:00 PM
Gevork Bagratyan
+ 2
But to answer your question. Use strncpy: //50 represents size strncpy(array2, array1, 50);
30th Jan 2020, 5:12 PM
Gevork Bagratyan
+ 1
Gevork! I would love to use string but this is my project and our teacher asked not to use string anywhere in the project (strange but true) but I still used string array without structure and it is working fine...
30th Jan 2020, 6:48 PM
Faisal Ur Rehman
Faisal Ur Rehman - avatar
0
Ah alright, glad it's working!
30th Jan 2020, 6:49 PM
Gevork Bagratyan