RunTime Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • itxharsh
    New Member
    • Nov 2009
    • 4

    RunTime Error

    Code:
    /*When i run the program i get a run time error Your code has stopped its execution with a non-zero (failure) exit value.This is generally due to run time Exceptions like Memory Access Violation and Floating Point Exception. Please check your code for run time Exceptions and try again.*/
    
    /* Header File "nonpreemptive.h"
    
    class NonPreemptive
    {
     public:
     	int* getWaitingTime(int* process, int* arrivalTime, int* burstTime, int nProcess);
    };  */
    
    #include<iostream>
    #include"nonpreemptive.h"
    using namespace std;
    NonPreemptive s1;
    int* NonPreemptive::getWaitingTime(int* process, int* arrivalTime, int* burstTime, int nProcess)
    {
    if(arrivalTime[0]!=0)
    {
    return NULL;
    }
    int g=0,h=0;
    for(g=0;g<nProcess;++g)
    {
    for(h=g+1;h<nProcess;++h)
    {
    if(arrivalTime[g]==arrivalTime[h])
    {
    return NULL;
    }
    if(arrivalTime[g]>arrivalTime[h])
    {
    return NULL;
    }
    if(burstTime[g]<0||burstTime[g]>10)
    {
    return NULL;
    }
    }
    }
    int done=0,min=0,CPU=0,x=0,i=0;
    int* result;
    while(done<nProcess)
    {
    min=20000;
    for(i=0;i<nProcess;++i)
    {
    if(process[i]>0)
    {
    if(arrivalTime[i]<=CPU)
    {
    if(arrivalTime[i]+burstTime[i]<min)
    {
    min=arrivalTime[i]+burstTime[i];
    x=i;
    }
    }
    }
    }
    result[x]=CPU-arrivalTime[x];
    CPU+=burstTime[x];
    ++done;
    process[x]=-1;
    }
    return result;
    }
    int main()
    {
    	{	int* output;	
    		int nProcess = 7;
    		int* process = (int*)malloc(sizeof(int) * nProcess);
    		int* arrivalTime = (int*)malloc(sizeof(int) * nProcess);
    		int* burstTime = (int*)malloc(sizeof(int) * nProcess);
    		
    		int proc[] = {1,2,3,4,5,6,7};
    		int aTime[] = {0,2,4,6,8,10,12};
    		int bTime[] = {6,2,5,4,1,3,5};
    		
    		for(int i=0;i<nProcess;i++)
    {
    			process[i] = proc[i];
    			arrivalTime[i] = aTime[i];
    			burstTime[i] = bTime[i];
    		}
    
    		output = s1.getWaitingTime(process, arrivalTime, burstTime, nProcess);
    		printf("\n");
    		if(output != NULL)
    			for(int i=0;i<nProcess;i++)
    				printf ("%d, ",output[i]);
    		else printf("NULL");
    	}
    return(0);
    }
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    Works for me. Where exactly it crashed?

    Comment

    Working...