c - 尝试初始化时 undefined reference

标签 c function undefined

我正在为 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/

相关文章:

javascript - 在未定义上使用严格相等会引发错误吗?

html - 为什么 IE9 及更高版本会抛出 undefined variable /子错误,而 IE8 不会

c - 将文件中的数据输入到数据结构中

c - 即使我向它发送 SIGABRT,子进程也会正常退出

javascript - 更新函数返回的数组

arrays - 在函数中向数组添加元素,但数组仍为空

JavaScript:变量未定义

c - 指向指针: What datatype with variable length strings?的指针

c - 如何测量计算时间

sql - 基于郁金香指标的 C 语言函数,使用 postgresql 计算 RSI