我正在尝试返回一个字符数组,但是出现了上面显示的错误。我是编程新手,所以我并不了解。预先感谢您的帮助。
int* printParty(int party)
{
char* partyArr = (char*)malloc(sizeof(char) * 15);
switch (party)
{
case 1:
strncpy(partyArr, "Constitution", 15);
break;
case 2:
strncpy(partyArr, "Democrat", 15);;
break;
case 3:
strncpy(partyArr, "Green", 15);
break;
case 4:
strncpy(partyArr,"Libertarian", 15);
break;
case 5:
strncpy(partyArr, "Republican", 15);
break;
default:
printf("Not a valid input.");
}
return partyArr;
}