Yes char
arrays are not assignable just as all arrays aren't. You should use strcpy
for example
strcpy(class, "Warrior");
and so on.
Also, you don't need to declare char class[30];
the longest string I see in your code is "undefined"
so
char class[10];
should be ok, 9
characters of "undefined"
+ 1 null terminating byte ''
.
And you should prevent buffer overflow with scanf
this way
scanf("%1s", class);
since you only want to read 1
character, also the comparison should be simpler just
if (class[0] == 'M')
strcpy(class, "Mage");
or even thsi would be more readable
classchosen = 1;
switch (class[0])
{
case 'M':
strcpy(class, "Mage");
break;
case 'R':
strcpy(class, "Ranger");
break;
case 'W':
strcpy(class, "Warrior");
break;
default:
classchosen = 0;
}
and finally check that scanf
actually succeeded, it returns the number of arguments matched so in your case a check would be like
if (scanf("%1s", class) == 1) ...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…