Thread: CPU scheaduling algorithm: undefinied symbol

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    34

    CPU scheaduling algorithm: undefinied symbol

    Code:
    #include<conio.h>
    #include<stdio.h>
    #include<dos.h>
    #define x 20
    
    
    struct info1
     {
     int at,bt,prior,tt,wt,no;
     }job[x];
    int q;
    
     int fcfs(struct info1 job[],int njobs);
     int sjf(struct info1 job[],int njobs);
     int np(struct info1 job[],int njobs);
     int rr(struct info1 job[],int njobs,int q);
     int srtf(struct info1 job[],int njobs);
     int pp(struct info1 job[],int njobs);
     void editmenu(struct info1 job[],int njobs);
    
    void main()
    {
    int choice,ctr,end,end2,njobs;
    float buff;
    
      printf("\t How many jobs would you like to be processed: ",x);
      scanf("%d",&njobs);
      if(njobs<=1||njobs>x)
         {
       
      clrscr();
        printf("\t Enter the arrival time of the jobs:\n\n\t\tJobs\tArrival Time\n\n");
      for(ctr=1;ctr<=njobs;ctr++)
          {
       printf("\t\t%d\t    ",ctr);
       scanf("%d",&job[ctr-1].at);
          }
      
      clrscr();
      printf("\t Enter the burst time of the jobs:\n\n\t\tJobs\tArrival Time\tBurst Time\n\n");
      for(ctr=1;ctr<=njobs;ctr++)
          {
       printf("\t\t%d\t    %d\t\t    ",ctr,job[ctr-1].at);
       scanf("%d",&job[ctr-1].bt);
          }
      
      clrscr();
      printf("\t Enter the priority of the jobs:\n\n\t\tJobs\tArrival Time\tBurst Time\tPriority\n\n");
      for(ctr=1;ctr<=njobs;ctr++)
          {
       printf("\t\t%d\t    %d\t\t    %d\t\t   ",ctr,job[ctr-1].at,job[ctr-1].bt);
       scanf("%d",&job[ctr-1].prior);
          }
      
      clrscr();
      printf("\n\t\tEnter time quantum/slice value: ");
      scanf("%d",&q);
         {
        
          
         }
      clrscr();
      printf("\n\n\t\tJobs\tArrival Time\tBurst Time\tPriority\n\n");
      for(ctr=1;ctr<=njobs;ctr++)
    	 {
    	 printf("\t\t%d\t    %d\t\t    %d\t\t   %d\n",ctr,job[ctr-1].at,job[ctr-1].bt,job[ctr-1].prior);
    
    	 printf("\n\t\t\t\t q= %d",q);
    
      printf("\n\n\n\t What cpu scheduling algorithm would you want to do? : ");
      printf("\n\n\t      [1]      (FCFS)      First Come First Serve");
      printf("\n\n\t      [2]      (SJF)       Shortest Job First");
      printf("\n\n\t      [3]      (SRTF)      Shortest Remaining Time First");
      printf("\n\n\t      [4]      (NP)        Non-preemptive Prioriry ");
      printf("\n\n\t      [5]      (PP)        Preemptive Priority");
      printf("\n\n\t      [6]      (RR)        Round Robin");
      printf("\n\n\t      [7]                  E       D      I      T");
      printf("\n\n\t      [8]                  E       X      I      T");
    
          printf("\n\t\n\n\t\tEnter choice: ",c);
          scanf("%d",&c);
    
           if(c==1)
           { fcfs(jb,a);
           getch();
    
            }
           else
    	 getch();
    	}
           }
    
    
    
    int fcfs(struct info1 job[],int njobs);
    
    
    {
    struct info2
     {
     int btleft,no,tt,wt;
     }queue[number];
    int jleft,time1=0,time2=0,timetemp=0,timeidle=0,ctr1=0,ctr2=0,end=0,idle=0,i1=1,i2=0,x=4,y=6,ytemp;
    float ttimeavg=0,wtimeavg=0;
    jleft=njobs;
    clrscr();
    printf("\n\n\tGantt Chart: (Press any key to continue)");
    gotoxy(4,9);cprintf("0");
    ytemp=y;
    for(ctr1=0;ctr1<number;ctr1++)
     {
     queue[ctr1].btleft=0;
     queue[ctr1].no=0;
     queue[ctr1].tt=0;
     queue[ctr1].wt=0;
     }
    while(end!=1)
     {
     for(ctr1=0;ctr1<njobs;ctr1++)
      {
      if(time1==job[ctr1].at)
       {
       queue[ctr2].btleft=job[ctr1].bt;
       queue[ctr2].no=job[ctr1].no;
       queue[ctr2].tt=0;
       queue[ctr2].wt=0;
       ctr2++;
       i1=0;
       }
      else i2=1;
      }
     if(i1==1&&i2==1&&queue[0].no==0)
      {
      idle=1;timeidle++;
      }
     else
      {
      if(idle==1)
       {
       y=ytemp;
       gotoxy(x,y);
       cprintf("ÉÍÍÍÍÍÍÍ»");
       gotoxy(x,++y);
       cprintf("º I(%2d) º",timeidle);
       gotoxy(x,++y);
       cprintf("ÈÍÍÍÍÍÍͼ");
       gotoxy(x+8,++y);
       cprintf("%d",time1);
       timetemp=time1;
       x=x+8;
       if(x+8>80)
        {
        x=4;
        y=y+5;
        gotoxy(4,y);cprintf("%d",timetemp);
        ytemp=ytemp+5;
        }
       timeidle=0;idle=0;
       }
      queue[0].btleft--;
      for(ctr1=0;ctr1<ctr2;ctr1++)queue[ctr1].tt++;
      for(ctr1=1;ctr1<ctr2;ctr1++)queue[ctr1].wt++;
      time1++;
      time2++;
      if(queue[0].btleft==0)
       {
       y=ytemp;
       gotoxy(x,y);
       cprintf("ÉÍÍÍÍÍÍÍ»");
       gotoxy(x,++y);
       cprintf("ºJ%2d(%2d)º",queue[0].no,time2);
       gotoxy(x,++y);
       cprintf("ÈÍÍÍÍÍÍͼ");
       gotoxy(x+8,++y);
       cprintf("%d",time1);
       timetemp=time1;
       x=x+8;
       if(x+8>80)
        {
        x=4;y=y+5;
        gotoxy(4,y);cprintf("%d",timetemp);
        ytemp=ytemp+5;
        }
       job[queue[0].no-1].wt=queue[0].wt;
       job[queue[0].no-1].tt=queue[0].tt;
       for(ctr1=0;ctr1<njobs;ctr1++)
        {
        queue[ctr1].btleft=queue[ctr1+1].btleft;
        queue[ctr1].no=queue[ctr1+1].no;
        queue[ctr1].wt=queue[ctr1+1].wt;
        queue[ctr1].tt=queue[ctr1+1].tt;
        }
       ctr2--;
       jleft--;
       time2=0;
       }
      }
     if(idle==1)time1++;
     i1=1;
     if(jleft==0)end=1;
     else end=0;
     }
    getch();
    clrscr();
    printf("\n\n\tComputation Table: (Press any key to continue)\n\n\t Job     TT      WT\n\tÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\n\t");
    for(ctr1=0;ctr1<njobs;ctr1++)
     {
     printf("%3d     %3d     %3d\n\t",ctr1+1,job[ctr1].tt,job[ctr1].wt);
     ttimeavg=ttimeavg+job[ctr1].tt;
     wtimeavg=wtimeavg+job[ctr1].wt;
     }
    printf("ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\n\tAvg\t%.2f\t%.2f\n\t",ttimeavg/njobs,wtimeavg/njobs);
    getch();
    return 1;
    }
    when i compiled it, it has no error but when i runned it.. it said:

    undefined symbol fcfs(info1 near *, int

    Please HELp!!! waaahhh!!!

  2. #2
    Registered User
    Join Date
    Apr 2007
    Posts
    45
    hmm, what was the full error?

    I believe in C, if you're calling a function before you define it, you need to declare it first (your declaration for fcfs looks like it's in the middle of the program, though it's hard to see without proper indentation).

    Besides that, what is 'jb'?
    we are one

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    1. Your indentation is still a mess.

    2. int fcfs(struct info1 job[],int njobs);
    Remove that ; if you want to define a function.

    Which is odd given that is supposedly compiles without this, it leads me to suspect that your main is missing a closing brace to begin with, and that what you have here is really just a long main function.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  3. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  4. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM
  5. <list>
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 02-24-2002, 04:07 PM