Solved

How to get function to return two node pointers

Posted on 2004-10-16
4
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

734 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