this code is not working as per its expected output.please tell me the errors and how to rectify them.

#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
int* getwaitingtime(int* proc,int* arr,int* bur,int noofproc)
{
int i,j,c[10],t,p,m,s[10],out[10],f,l;
int *wait;
for(i=0;i<noofproc;i++)
{
if((arr[0]!=0)||(arr[i]>arr[i+1])||(arr[i]==arr[i+1])||(bur[i]<0)||(bur[i]==0)||(bur[i]>10))
{
return NULL;
}
}
for(i=0;i<noofproc;i++)
{
c[i]=arr[i]+bur[i];
}
for(i=1;i<noofproc;i++)
{
  for(j=1;j<noofproc;j++)
  {
    if(c[j]>c[j+1])
     {
       t=c[j];
       c[j]=c[j+1];
       c[j+1]=t;
       p=arr[j];
       arr[j]=arr[j+1];
       arr[j+1]=p;
       m=bur[j];
       bur[j]=bur[j+1];
       bur[j+1]=m;
     }
  }
}
s[0]=c[0];
for(i=1;i<noofproc;i++)
 {
  s[i]=s[i-1]+bur[i];
 }
for(i=0;i<noofproc;i++)
 {
  out[i]=s[i]-(arr[i]+bur[i]);
 }
for(i=0;i<noofproc;i++)
 {
  for(j=0;j<(noofproc-1);j++)
   {
     if(arr[j]>arr[j+1])
     {
      f=arr[j];
      arr[j]=arr[j+1];
      arr[j+1]=f;
      l=out[j];
      out[j]=out[j+1];
      out[j+1]=l;
     }
   }
 }
wait=out;
return wait;
}

void main()
{
clrscr();
int arr[]={0,2,4,5},bur[]={7,4,1,4},proc[]={1,2,3,4},noofproc=4;
int *output[10],i;
output[10]=(*getwaitingtime)(proc,arr,bur,noofproc);
//if(output==NULL)
//{
//cout<<"wrong";
//}
//else
//{
for(i=0;i<noofproc;i++)
{
cout<<*(output[i])<<endl;
}
//}
getch();
}

Well, what is the expected output? I can't read minds.

well expected output is {0,6,3,7}.
The code is working correctly without pointers.so definitely there is mistake in using pointers..

<deleted>

>>output[10]=(*getwaitingtime)(proc,arr,bur,noofproc);

That is incorrect. It should be int* output = getwaitingtime(proc,arr,bur,noofproc); Then delete the declaration of output on line 69.

I havent yet got the correct answer.
there is some error in returning.
can someone sort that out please?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.