gpt4 book ai didi

连续 "undefined reference to..."

转载 作者:行者123 更新时间:2023-11-30 17:26:45 30 4
gpt4 key购买 nike

我正在开发一个程序,但我不断收到“对‘dosell’的 undefined reference ”,我不太明白发生了什么。这是函数的声明:

void dosell(int *cash, int *numchips);

函数的使用:

choice = menu();

// Execute the appropriate choice.
if (choice == 1) {
dobuy(&cash, &numchips);
}
else if (choice == 2) {
dosell(&cash, &numchips);
}

以及函数本身:

void dosell(int *cash, int *numchips) {

int numsell;

// Determine the number of chips to be sold.
printf("How many chips do you want to sell?\n");
scanf("%d", &numsell);

// Print out the error message if this is too much.
if (numsell > *numchips)
printf("Sorry, you do not have that many chips. No chips sold.\n");

// Execute the transaction.
else {
(*cash) += sellchips(numsell);
(*numchips) -= numsell;
}}}

最佳答案

将函数声明放在文件的开头,即在主函数之前、包含和定义之后:

void dosell(int *cash, int *numchips) ;

关于连续 "undefined reference to...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26660315/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com