Thread: the program can't call the function..HELP!!!

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

    the program can't call the function..HELP!!!

    Code:
    #include<conio.h>
    #include<stdio.h>
    #include<dos.h>
    # define x 25
    
    struct data
     {
     int at,bt,priority,tt,wt,no;
     }jb[x];
    
    int a,b, c, y, njbs;
    
    
     int fcfs(struct data jb[], int a);
    
     void main()
      {
      int d, end,end2;
      clrscr();
      printf("\t How many jobs shall be processed?: ",a);
      scanf("%d",&a);
           {
    	clrscr();
    	printf("\t Enter the arrival time of the jobs:\n\n\t\tJobs\tArrival Time\n\n");
    	for(b=1;b<=a;b++)
    	     {
    	     printf("\t\t%d\t    ",b);
    	     scanf("%d",&jb[b-1].at);
    	      }
    
    	clrscr();
    	printf("\t Enter the burst time of the jobs:\n\n\t\tJobs\tArrival Time\tBurst Time\n\n");
    	for(b=1;b<=a;b++)
    	       {
    	printf("\t\t%d\t    %d\t\t    ",b,jb[b-1].at);
    	scanf("%d",&jb[b-1].bt);
    	}
    
    	clrscr();
    	printf("\t¯ Enter the priority of the jobs:\n\n\t\tJobs\tArrival Time\tBurst Time\tPriority\n\n");
    	for(b=1;b<=a;b++)
    	{
    
    	printf("\t\t%d\t    %d\t\t    %d\t\t   ",b,jb[b-1].at,jb[b-1].bt);
    	scanf("%d",&jb[b-1].priority);
    	}
    
    	clrscr();
    	printf("\t¯ Enter the time quantum/ time slice:\n\n\t\tJobs\tArrival Time\tBurst Time\tPriority\n\n");
    	   for(b=1;b<=a;b++)
    		{
    	   printf("\t\t%d\t    %d\t\t    %d\t\t   %d\n",b,jb[b-1].at,jb[b-1].bt,jb[b-1].priority);
    		 }
    
    	 clrscr();
    	 printf("\n\t\tEnter time quantum/ time slice value: ");
    	 scanf("%d",&y);
    
    	  }
    
    
    	 {
      clrscr();
      printf("\n\n\t\tJobs\tArrival Time\tBurst Time\tPriority\n\n");
      for(b=1;b<=a; b++)
    	 {
    	 printf("\t\t%d\t    %d\t\t    %d\t\t   %d\n",b,jb[b-1].at,jb[b-1].bt,jb[b-1].priority);
    	 }
    
    	 printf("\n\t\t\t\t q= %d",y);
    
      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 data jb[], int a)
    {
    struct info
     {
     int btleft,no,tt,wt;
     }queue[x];
    
    float ttimeavg=0,wtimeavg=0;
    
    clrscr();
    for(b=0;b<=a; b++)
     {
     printf("%3d     %3d     %3d\n\t",b+1,jb[b].tt,jb[b].wt);
     ttimeavg=ttimeavg+jb[b].tt;
     wtimeavg=wtimeavg+jb[b].wt;
     }
    printf("\n\tAvg\t%.2f\t%.2f\n\t",ttimeavg/njbs,wtimeavg/njbs);
    return 0;
    }
    THE FCFS function......

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    I have no idea what your question is. Could you please clarify?

    After removing the annoying compiler-specific calls to clrscr(), I was able to build. It ran, the function was called.

    Are you really running on DOS?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    34
    if I choose 1(FCFS algorithm), the program terminates....



    What's wrong with this function???
    Code:
    int fcfs(struct data jb[], int a)
    {
    struct info
     {
     int btleft,no,tt,wt;
     }queue[x];
    
    float ttimeavg=0,wtimeavg=0;
    
    clrscr();
    for(b=0;b<=a; b++)
     {
     printf("&#37;3d     %3d     %3d\n\t",b+1,jb[b].tt,jb[b].wt);
     ttimeavg=ttimeavg+jb[b].tt;
     wtimeavg=wtimeavg+jb[b].wt;
     }
    printf("\n\tAvg\t%.2f\t%.2f\n\t",ttimeavg/njbs,wtimeavg/njbs);
    return 0;
    }

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Division by zero. Where does njbs get a value other than the zero it is initialized with.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Well thats what u have programmed. Once the function fcfs function returns to main, u get char and comes out of main. Well it would fine for me. But dunno what output to expect.

    ssharish

  6. #6
    Registered User
    Join Date
    Dec 2006
    Posts
    34
    actually this is the original function to be called, we've just edited some of the variables.

    Code:
    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("&#201;&#205;&#205;&#205;&#205;&#205;&#205;&#205;&#187;");
       gotoxy(x,++y);
       cprintf("&#186; I(&#37;2d) &#186;",timeidle);
       gotoxy(x,++y);
       cprintf("&#200;&#205;&#205;&#205;&#205;&#205;&#205;&#205;&#188;");
       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("&#201;&#205;&#205;&#205;&#205;&#205;&#205;&#205;&#187;");
       gotoxy(x,++y);
       cprintf("&#186;J%2d(%2d)&#186;",queue[0].no,time2);
       gotoxy(x,++y);
       cprintf("&#200;&#205;&#205;&#205;&#205;&#205;&#205;&#205;&#188;");
       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&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;\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("&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;&#196;\n\tAvg\t%.2f\t%.2f\n\t",ttimeavg/njobs,wtimeavg/njobs);
    getch();
    return 1;
    }

  7. #7
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Ohh god, you need a proper code indendation. Its very difficult to read a code like that

    ssharish

  8. #8
    Registered User
    Join Date
    Dec 2006
    Posts
    34
    It should show a gantt chart and the average waiting time and turn around time using fcfs when called.

  9. #9
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    M'kay. I'm having a hard time debugging "pretend" code. And the fact that it isn't portable isn't doing you any favors. I guess I'll leave this to others with interest.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  10. #10
    Registered User
    Join Date
    Dec 2006
    Posts
    34
    sorry for the inconvenience.. it's just that we are already cramming bcoz it is due on the 27 th....

  11. #11
    Registered User
    Join Date
    Dec 2006
    Posts
    34
    I've replaced the njbs with the variable a.. and it worked! the function can now be called! THanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  2. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 07:26 PM
  3. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. function
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 06-02-2002, 07:38 PM