+ 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
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.
+ 2
But to answer your question. Use strncpy:
//50 represents size
strncpy(array2, array1, 50);
+ 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...
0
Ah alright, glad it's working!