未定义的引用错误

时间:2015-05-29 10:57:59

标签: c function compiler-errors undefined-reference

我的程序无法正确编译。它给出了未定义的错误。有人可以帮我解决这个问题吗?它说

  

C:\ Users \ Milan_2 \ AppData \ Local \ Temp \ ccQt3lVs.o在功能中   ' orderOnConveyer':90 C:\ Users \ Milan_2 \ Desktop \ Untitled2.c undefined   参考'插入'

     

C:\ Users \ Milan_2 \ AppData \ Local \ Temp \ ccQt3lVs.o在功能' WTandTAT':   115 C:\ Users \ Milan_2 \ Desktop \ Untitled2.c未定义引用   '的isEmpty' C:\ Users \ Milan_2 \ AppData \ Local \ Temp \ ccQt3lVs.o In   功能'主要':

#include <stdio.h>
#include <conio.h>
#include <malloc.h>
#define MAX1 30
#define MAX2 30
#define TRUE 1
#define FALSE 0

struct cake{
    char cake;
    int preperation_time;
    int baking_time;
    int waiting_time;
    int turnaround_time;
};
struct Queue{
    int front;
    int rear;
    int count;
    struct cake items[MAX1];
};
struct Stack{
    int top;
    struct cake items[MAX2];
};

struct cake ChocolateCake();
struct cake SpongeCake();
struct cake MeringueCake();
struct cake RedVelvetCake();

void orderOnConveyer(struct Queue *, int);
void WTandTAT(struct Queue *,struct Queue *, int);
int longestBakingTime(struct Queue *q);
void orderOnStorageConveyer(struct Queue *, struct Stack *);
void averageWaitingTime_and_averageTurnaroundTime(struct Queue *, struct Queue *);

void init(struct Queue *);
int isFull(struct Queue *);
void insert(struct Queue *, struct cake);


void push(struct Stack *, struct cake);

struct cake pop(struct Stack *);

struct cake ChocolateCake(){
     struct cake c;
     c.cake='C';
     c.preperation_time=25;        
     c.baking_time=40;             
     c.waiting_time=0;
     c.turnaround_time=0;
     return c;
}
struct cake SpongeCake(){
     struct cake c;
     c.cake='S';
     c.preperation_time=30;
     c.baking_time=20;           
     c.waiting_time=0;
     c.turnaround_time=0;
     return c;
}
struct cake MeringueCake(){
     struct cake c;
     c.cake='M';
     c.preperation_time=45;
     c.baking_time=75;           
     c.waiting_time=0;
     c.turnaround_time=0;
     return c;
}
struct cake RedVelvetCake(){
     struct cake c;
     c.cake='R';
     c.preperation_time=60;
     c.baking_time=30;          
     c.waiting_time=0;
     c.turnaround_time=0;
     return c;
}

void orderOnConveyer(struct Queue *q, int minute){
     int i;
     printf("\n\n\n\n----------Conveyer Order----------\n\n\n");
     for(i=1;i<=minute;i++){
         if(i%25==0){
            printf("\nChocolate Cake");
            insert(q, ChocolateCake());
         }
         if(i%30==0){
            printf("\nSponge Cake");
            insert(q, SpongeCake());
         }
         if(i%45==0){
            printf("\nMeringue Cake");
            insert(q, MeringueCake());
         }
         if(i%60==0){
            printf("\nRedVelvet Cake");
            insert(q, RedVelvetCake());
         }
     }    
}


void WTandTAT(struct Queue *q, struct Queue *q1, int minute){
         struct cake temp;
         int i,temp1=0,temp2=0,temp3=0,temp4=0;

         printf("\n\n\n------- Waiting Time & Turnaround Time for each cake -------\n\n");
         printf("Cake\tWaiting Time\tTurnaround Time");

         while(!isEmpty(q)){


         if(temp.preperation_time==25){

              for( i=temp.preperation_time+temp1;i<minute;i++){
                  temp.waiting_time++;   
         }
              temp1=temp1+temp.preperation_time;
              temp.turnaround_time=temp.baking_time+temp.waiting_time;
              insert(q1, temp);   
         }

         else if(temp.preperation_time==30){

              for( i=temp.preperation_time+temp2;i<minute;i++){
                  temp.waiting_time++;    
              }

              temp2=temp2+temp.preperation_time;
              temp.turnaround_time=temp.baking_time+temp.waiting_time;

              insert(q1, temp);

         }
         else if(temp.preperation_time==45){

              for( i=temp.preperation_time+temp3;i<minute;i++){
                  temp.waiting_time++; 
              }

              temp3=temp3+temp.preperation_time;
              temp.turnaround_time=temp.baking_time+temp.waiting_time;

              insert(q1, temp);

         }
         else if(temp.preperation_time==60){

              for( i=temp.preperation_time+temp4;i<minute;i++){
                  temp.waiting_time++;  
          }

              temp4=temp4+temp.preperation_time;
              temp.turnaround_time=temp.baking_time+temp.waiting_time;

              insert(q1, temp);

         }
         }

}


void averageWaitingTime_and_averageTurnaroundTime(struct Queue *q, struct Queue *q1)
 {
      struct cake temp;
      int Total_waiting_time=0, count=q->count, Total_turnaround_time=0;
      float avgWT=0, avgTAT=0;
      while(!isEmpty(q)){



            Total_waiting_time=Total_waiting_time+temp.waiting_time;
            avgWT=(Total_waiting_time/count);

            Total_turnaround_time=Total_turnaround_time+temp.turnaround_time;
            avgTAT=(Total_turnaround_time/count);
            insert(q1,temp);
      }
      printf("\n\n------------------------------------------------------------------------");        
      printf("\n\nAvarage Waiting Time =  %f min",avgWT);
      printf("\n\nAvarage Turnaround Time =  %f min",avgTAT);            
}


main(){
     struct Queue q;
     struct Queue q1;
     struct Stack s;
     struct cake temp;
     int minute, i=0;

     s.top=-1; 
     init(&q); 
     init(&q1);

     printf("*******************Welcome Bakery Simulation*******************");
     printf("\n\t\t       Author : Milan Udayanga( )");
     printf("\n--------------------------------------------------------------------------------");

     printf("\n\nEnter the duration(minute) for check the process in the bakery:");
     scanf("%d",&minute);



    orderOnConveyer(&q, minute);

    WTandTAT(&q, &q1, minute);

    while(!isEmpty(&q1)){

        printf("\n%c\t%d\t\t%d", temp.cake, temp.waiting_time, temp.turnaround_time);
        insert(&q,temp);
   }

    averageWaitingTime_and_averageTurnaroundTime(&q, &q1);

    orderOnStorageConveyer(&q1, &s);

    while(!isEmpty(&s)){
        temp= pop(&s);
        printf("\n%c",temp.cake);

   }
    getch();
    return 0;
}

1 个答案:

答案 0 :(得分:1)

在您的代码中,

  1. 对于insert()函数,您只有声明函数(作为原型)。你没有在这里定义这个功能。您需要有一个功能定义。

  2. 对于isEmpty(),您既没有声明也没有定义。在这种情况下,编译器不知道该怎么做。所以,它说,“未定义参考”