Solved

How to get function to return two node pointers

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

Technology Partners: 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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
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.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

729 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