Workaround: Use the strcpy function for string copy prototype declaration: Char *strcpy (char* dest, const char *src); header file: #include <string.h> and #include < stdio.h> function: Copy a string starting from the SRC address and containing a null terminator to the address space beginning with dest: src and dest memory areas cannot overlap and dest must have enough space to accommodate the SRC string. Returns a pointer to the dest.
1 //testArray.cpp: Defines the entry point of the console application. 2 3#include"stdafx.h"4#include"string.h"5 6 #defineMax_age_size 1207 #defineMax_name_size 1008 9typedefenum{//enumeration value DefinitionsTenWalking =1, Onerunning =2, ASwimming =3, -Jumpping =4, -Sleeping =5 the }hobby; - -typedefenum{ -Chinese =1, +中文版 =2, -Japanese =3 + }language; A attypedefstructpeople{//definition of structural body -union{//Union definition, use method and struct similar - struct{ - CharAge[max_age_size]; - CharName[max_name_size]; - }child; in Hobby Hobby; - Language Language; to }student; + }people; - the * int_tmain (intARGC, _tchar*argv[]) $ { Panax Notoginseng CharName1[max_name_size] = {"test1"}; - CharName2[max_name_size] = {"test2"}; the +People p[2]; A //P[0]. Student.Child.age = "Ten";//Error: The expression must be a modifiable lvalue (reason: string cannot be assigned directly) thestrcpy (p[0]. Student.Child.age,"Ten");//using the strcpy function for string copying +strcpy (p[0]. STUDENT.CHILD.NAME,NAME1); -p[0]. Student.hobby =walking; $p[0]. Student.language =Chinese; $ -strcpy (p[1]. Student.Child.age," A"); -strcpy (p[1]. STUDENT.CHILD.NAME,NAME2); thep[1]. Student.hobby =running; -p[1]. Student.language =中文版;Wuyi theprintf"Student1 ' s name:%s\n", p[0]. Student.Child.name); - return 0; Wu}
C language Execution times error "The expression must be a modifiable lvalue and cannot be converted from" const char [3] "to" char [120] ", because the string cannot be directly assigned