[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to get function to return two node pointers

Posted on 2004-10-16
4
Medium Priority
?
245 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 1000 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

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
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 structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

650 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