警告:从不兼容的指针类型返回[默认启用]

时间:2019-01-30 02:19:32

标签: c compiler-errors

我正在尝试返回一个字符数组,但是出现了上面显示的错误。我是编程新手,所以我并不了解。预先感谢您的帮助。

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;
}

0 个答案:

没有答案