gpt4 book ai didi

c - 尝试初始化时 undefined reference

转载 作者:行者123 更新时间:2023-11-30 20:15:20 24 4
gpt4 key购买 nike

我正在为 C 类入门项目做项目,但遇到了障碍...我要放弃测试阶段,所以请忽略所有打印语句。

这是代码块告诉我的内容:

 ERROR: undefined reference to `BUYTICKET'|

无论如何,当我尝试初始化该函数时遇到了麻烦。 (或称其为两者之一。)

这是我的代码:(为了窥探同学的可能性,省略了部分代码。

#include <stdio.h>
#include <stdlib.h>


int BUYTICKET (float price_of_ticket,float price_presold, int amt_of_tickets_sold);
// include functions here. you will need around 10
int main()
{
int i,j;

//opens file
FILE * ifp;
ifp = fopen("input.txt", "r");
//created variables for line one of text document
float price_pretickets,price_tickets;
int amt_presold;

//scan in first line.
fscanf(ifp, "%f", &price_pretickets);
fscanf(ifp, "%f", &price_tickets);
fscanf(ifp, "%d", &amt_presold);
printf("%f %f %d\n", price_pretickets,price_tickets, amt_presold);
//Scaning in the second line of code

int num_of_events;
fscanf(ifp, "%d", &num_of_events);
printf("\n%d\n", num_of_events);
int c =0;
char command[16];
while (c<num_of_events)
{
c++;

fscanf(ifp, "%s", command);
printf("%s", command);

int amt_of_tickets_sold;
if (strcmp(command, "BUY") == 0)
{
fscanf(ifp, "%s", command);
printf(" %s ", command );
if (strcmp(command, "TICKET")== 0)
{

BUYTICKET(price_tickets, price_pretickets,amt_presold); //ERROR!!
fscanf(ifp, "%s", command);
printf("\n %s\n", command);

//function


}

else if (strcmp(command, "RAFFLE") == 0){
fscanf(ifp, "%s", command);
printf("\n%s\n", command);
}
else if (strcmp(command, "DRINK")==0)
;//function for buy raffle
}
else if (strcmp(command, "BIDTERM")==0)
;//function for BIDTERM
else if (strcmp(command, "CLOSEAUCTION")==0)
;//function for CLOSEAUCTION
else if (strcmp(command, "AWARD")==0)
fscanf(ifp, "%c", &command);
if (strcmp(command, "RAFFLE")==0)
{
}//function for raffle
else if (strcmp(command, "AUCTION")==0)
;//function for AUCTION
else if (strcmp(command, "PERSON")==0)
;//function for AWARD PERSON

else if (strcmp(command, "TOTAL")==0){
fscanf(ifp,"%s", command);
printf(" %s ", command);
}

}

//go ahead and determine the actions the text documents wants you to take using if statements.
// use strcmp to compare between buy tcikets buy drink ect.
//




int BUYTICKET(float price_of_ticket,float price_presold, int amt_of_tickets_sold)
{

printf("%f %f %d", price_of_ticket,price_presold, amt_of_tickets_sold);

}


return 0;


}

谢谢你们帮我解决问题!

最佳答案

您正在主函数内定义BUYTICKET函数。在外部定义它。

通常不能在其他函数中定义函数。

关于c - 尝试初始化时 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20171027/

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