尝试初始化时未定义的引用

时间:2013-11-24 04:20:18

标签: 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;


}

让你们看看我的问题!

2 个答案:

答案 0 :(得分:2)

您正在主函数中定义BUYTICKET函数。在外面定义它。

您通常无法在其他函数中定义函数。

答案 1 :(得分:0)

函数定义不能出现在其他函数的定义中。你在main中定义BUYTICKET是非法的。