Hello All,

I am trying to simulate a scheduling algorithm.
I am getting "segmentation fault" as error.
I am pinpointing the line on which there is error.

Here is the code:

#include<iostream.h>
#include<stdio.h>

struct process
{
    int pid, arrtime, srvtime, ftime, processor;
};
struct process p[2];

struct node
{
    node *next;
    process *proc;
};

int q;

node *first = NULL;

void insert0(process *a)
{
    cout<<"Before\n";
    if(first == NULL)
    {
        cout<<"if first == Null\n";
        first->proc = a; ///////////////////////////////////// Here is the error
        cout<<"after\n";
        first->next = NULL;
        
    }
    else
    {
        node *temp = first;
        while(temp->next != NULL)
        {
            temp = temp->next;
        }
        node *r;
        r->next = NULL;
        r->proc = a;
        temp->next = r;
        
    }
    cout<<"first->proc->pid  "<<first->proc->arrtime;
    cout<<"first->proc->arrtime  "<<first->proc->arrtime<<endl;
    cout<<"first->next->proc->pid  "<<first->proc->arrtime;
    cout<<"first->next->proc->arrtime  "<<first->proc->arrtime;
}

process * remove0()
{
    
}

int main()
{
    cout<<"enter processes"<<endl;
    for(int i = 0; i<2; i++)
    {
        cin>>p[i].pid;
    }
    cout<<"Enter their arrval time"<<endl;
    for(int i = 0;i<2;i++)
    {
        cin>>p[i].arrtime;
    }
    
    for(int i = 0; i<2; i++)
    {
        insert0(&p[i]);
    }
    return 0;
} 



Please tell me what is the mistake?

Thanks and Regards.

 
---------------------------------
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.

[Non-text portions of this message have been removed]

Reply via email to