Solved

How to get function to return two node pointers

Posted on 2004-10-16
4
237 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now