7 Replies - 2408 Views - Last Post: 20 January 2009 - 09:23 AM Rate Topic: -----

#1 smee1012  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 17-January 09

SJF algorithym

Posted 17 January 2009 - 11:31 PM

can u help me whats wrong with this code?...there's no error with the code but when i run it its said that abnormal program termination,null poinetr assigment..can u help me plss asap cause i badly need it...thanks in advance,,

#include<stdio.h>
main()


	{
	float avgwt,avgtt;

	char pname[10][10],c[10][10];
	int wt[10],tt[10],bt[10],at[1],t,q,i,n=10,sum=0,sbt=0,ttime,j,ss=0;
	int randomp=rand() % 5+5;
	int randomb=rand() % 1+9;
   {
	printf("\t\n Process Name :");
	for(i=0;i<n;i++)
		{

	printf("%s",&pname[i][randomp] );
	printf("%s",&bt[randomb] );

	}

	for(i=0;i<n;i++)

	for(j=i+1;j<n;j++)


		{
		if(at[i]==at[j])
		if(bt[i]>bt[j])


			{
			t=at[i];
			at[i]=at[j];
			at[j]=t;
			q=bt[i];

			bt[i]=bt[j];
			bt[j]=q;
			strcpy(c[i],pname[i]);
			strcpy(pname[i],pname[j]);
			strcpy(pname[j],c[i]);
		}

		if(at[i]!=at[j])
		if(bt[i]>bt[j])



			{
			t=at[i];
			at[i]=at[j];
			at[j]=t;
			q=bt[i];
			bt[i]=bt[j];
			bt[j]=q;
			strcpy(c[i],pname[i]);
			strcpy(pname[i],pname[j]);

			strcpy(pname[j],c[i]);
		}

	}

	wt[0]=0;
	for(i=0;i<n;i++)


		{
		wt[i+1]=wt[i]+bt[i];
		sum=sum+(wt[i]-at[i]);
		sbt=sbt+(wt[i+1]-at[i]);

		tt[i]=wt[i]+bt[i];
		ss=ss+bt[i];
	}

	printf("\n\n GANTT CHART");
	printf("\n\n ------------------------------------------------------------------\n");
	for(i=0;i<n;i++)



		{
		printf("|\t%s\t",pname[i]);
		sbt=sbt+wt[i+1];
		tt[i]=wt[i]+bt[i];
		ss=ss+bt[i];
	}

	printf("\n\nGANTT CHART");
	printf("\n--------------------------------------------------------------------\n");

	for(i=0;i<n;i++)


		{
		printf("|\t%s\t",pname[i]);
	}

	printf("\n--------------------------------------------------------------------\n");
	for(i=0;i<n;i++)



		{
		printf("%d\t\t",wt[i]);
	}
	clrscr();
	printf("%d\n",ss);
	printf("\n--------------------------------------------------------------------\n");
	printf("\n\n Total WAITING TIME of the process=%d",sum);

	printf("\n\nTotal TURNAROUND TIME of the process=%d",sbt);
	avgwt=(float)sum/n;
	avgtt=(float)sbt/n;
	printf("\n\nAverage WAITING TIME of the process=%f",avgwt);
	printf("\n\nAverage TURNAROUND TIME of the process=%f",avgtt);

}


}


:code:

Is This A Good Question/Topic? 0
  • +

Replies To: SJF algorithym

#2 DoubleFission  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 24
  • View blog
  • Posts: 223
  • Joined: 20-September 08

Re: SJF algorithym

Posted 18 January 2009 - 03:40 AM

Someone please move this to C/C++ but:

you need to:

#include<stdlib.h>
#include<string.h>
#include<cstdlib>

and do a system("clear") instead of the clrscr().


And next time:

Don't forget to use [ code] [/ code] tags
Was This Post Helpful? 0
  • +
  • -

#3 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1377
  • View blog
  • Posts: 10,951
  • Joined: 06-February 08

Re: SJF algorithym

Posted 18 January 2009 - 03:56 AM

1) Please :code:
2) This forum is for questions related to DIC.
3) Moved to C/C++ :)
Was This Post Helpful? 0
  • +
  • -

#4 smee1012  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 3
  • Joined: 17-January 09

Re: SJF algorithym

Posted 20 January 2009 - 08:11 AM

I already did what you said but still its abnormal program termination and null pointer assigment...can you help me out of this code pls....i really need it...thanks in advance.. :D

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

main()


	{
	float avgwt,avgtt;
	char Process[10][10];

	int wt[10],tt[10],bt[10],at[1],t,q,i,n=11,sum=0,sbt=0,ttime,j,ss=0;
	int randomb=rand() % 1+9;
   {
	printf("\t\n Processes:");
	for(i=0;i<n;i++)
		{

	printf("%s",&Process[i],&bt[randomb]);

	}

	for(i=0;i<n;i++)

	for(j=i+1;j<n;j++)


		{

		if(bt[i]>bt[j])


			{

			q=bt[i];

			bt[i]=bt[j];
			bt[j]=q;

		}


	}


	printf("\n\nGANTT CHART");
	printf("\n--------------------------------------------------------------------\n");

	for(i=0;i<n;i++)


		{
	printf("|\t%s\t",Process[i]);
	}

	printf("\n--------------------------------------------------------------------\n");
	for(i=0;i<n;i++)



		{
		printf("%d\t\t",wt[i]);
	}
	wt[0]=0;
	for(i=0;i<n;i++)


		{
		wt[i+1]=wt[i]+bt[i];
	sum=bt[i]-wt[i];
	sbt=bt[i+1]-wt[i];

		tt[i]=wt[i]+bt[i];
		ss=ss+bt[i];
	}

	printf("\n\n GANTT CHART");
	printf("\n\n ------------------------------------------------------------------\n");
	for(i=0;i<n;i++)



		{
	printf("|\t%s\t",Process[i]);
		sbt=sbt+wt[i+1];
		tt[i]=wt[i]+bt[i];
		ss=ss+bt[i];
	}

   

	printf("%d\n",ss);
	printf("\n--------------------------------------------------------------------\n");
	printf("\n\n Total WAITING TIME of the process=%d",sum);

	printf("\n\nTotal TURNAROUND TIME of the process=%d",sbt);
	avgwt=(float)sum/n;
	avgtt=(float)sbt/n;
	printf("\n\nAverage WAITING TIME of the process=%f",avgwt);
	printf("\n\nAverage TURNAROUND TIME of the process=%f",avgtt);
	getch();
}


}

Was This Post Helpful? 0
  • +
  • -

#5 Drekey  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 24
  • Joined: 09-January 09

Re: SJF algorithym

Posted 20 January 2009 - 08:26 AM

int randomb=rand() % 1+9;
   {


maybe its a stupid question but, why the '{'?

and why do you close it in the end?
Was This Post Helpful? 0
  • +
  • -

#6 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: SJF algorithym

Posted 20 January 2009 - 08:40 AM

int randomb=rand() % 1+9;

The above is interpreted by the computer as,
Generate a random number between 0 and MaxInteger (2147483647), divide it by 1 and calculate the integer remainder (which is always 0), then add 9 and place the result in variable randomb. I.e the result is always 9.

This post has been edited by Gloin: 20 January 2009 - 08:41 AM

Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6036
  • View blog
  • Posts: 23,429
  • Joined: 23-August 08

Re: SJF algorithym

Posted 20 January 2009 - 09:18 AM

Then there's this abomination:

printf("%s",&Process[i],&bt[randomb]);


With totally uninitialized data.

To sort of paraphrase Dean Wormer: Copying and pasting code is no way to program.
Was This Post Helpful? 0
  • +
  • -

#8 Drekey  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 24
  • Joined: 09-January 09

Re: SJF algorithym

Posted 20 January 2009 - 09:23 AM

This code was totaly copy past, and it still needs a lot of work done on it.

I do belive the error you were asking its due to some loose { } around the code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1