Solved

How to get function to return two node pointers

Posted on 2004-10-16
4
239 Views
Last Modified: 2010-04-15
I have this function say

struct node *search_job_queue(struct queue *job_queue, struct queue *memory_map, struct node *job_node_ptr)
{
      struct node *job_node;
      struct node *mem_node;

      for(job_node = job_queue->head; job_node != NULL; job_node = job_node->next)
      {
            for(mem_node = memory_map->head; mem_node != NULL; mem_node = mem_node->next)
            {
                  if(mem_node->data == NULL) /* indicates that node is a free hole in main memory */
                  {
                        if(job_node->data->resources_needed <= mem_node->partition_size)
                        {
                              job_node_ptr = job_node;                        
                              return(mem_node);
                        }
                  }
            }
      }
      job_node_ptr = NULL;
      return(NULL);
}

The memory node is returned alright as it uses a return call, but I have passed a null job_node_ptr to the function to assign the address of
a particular job node but in the calling function the job_node_ptr is null so this statement doesn't appear to have worked as I intended
job_node_ptr = job_node;

Any help would be appreaciated

 
0
Comment
Question by:Broken_Arrow
  • 3
4 Comments
 
LVL 5

Expert Comment

by:van_dy
ID: 12326353
Hi,

 In the calling function you might have something like this;

node *job_node_ptr = NULL;
.
.
.
search_job_que(job_queue, memory_map, &job_node_ptr)

and do the following change in search_job_que;

struct node *search_job_queue(struct queue *job_queue, struct queue *memory_map, struct node *j*ob_node_ptr)
{
     struct node *job_node;
     struct node *mem_node;

     for(job_node = job_queue->head; job_node != NULL; job_node = job_node->next)
     {
          for(mem_node = memory_map->head; mem_node != NULL; mem_node = mem_node->next)
          {
               if(mem_node->data == NULL) /* indicates that node is a free hole in main memory */
               {
                    if(job_node->data->resources_needed <= mem_node->partition_size)
                    {
                         (*job_node_ptr) = job_node;                    
                         return(mem_node);
                    }
               }
          }
     }
     job_node_ptr = NULL;
     return(NULL);
}

It should work fine then.
hope this helps,
van_dy.
0
 
LVL 5

Accepted Solution

by:
van_dy earned 250 total points
ID: 12326357
oops i meant:

struct node *search_job_queue(struct queue *job_queue, struct queue *memory_map, struct node **job_node_ptr)
0
 

Author Comment

by:Broken_Arrow
ID: 12326370
Thanks that fixed up everything nicely, thanks very much
0
 
LVL 5

Expert Comment

by:van_dy
ID: 12326374
Glad that I could help.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question