Solved

function procedure design

Posted on 2006-11-12
4
223 Views
Last Modified: 2010-04-15
hi,
I have a program like below:
the problem is the backtrack() will return me more than one set of (newt[N][i][j] != 0), but only first set goes to addpath(N, i, j). how can I let the program run every set of  (newt[N][i][j] != 0)?


---------------------------------------
main ()
{
backtrack();
system("pause");
return 0;
}

void backtrack(void)
{
   for (i=0; i<3;i++){  
      for (j=0; j<3; j++) {
           if (newt[N][i][j] != 0)
           {    
               addpath(N, i, j);        
            }//end if
       }// 3rd for      
      } // 2nd for  
}
----------------------------------------------------------------------------

<ps> the addpath(N, i, j) will continue call other functions.....but I am sure that the final function is looks like

void addpath (int s, int i, int j)
{
  if( s == 0 )
  {
    printf("final path is %d%d%d : \n",s,i,j);
    printf("finish!!\n");-------------------------------------------->> end here
    return;
  }
   call other functions....
}
0
Comment
Question by:rmtogether
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
PaulCaswell earned 400 total points
ID: 17926625
Hi rmtogether,

Where are i and j declared? If they are declared global then they are probably being changed elsewhere.

Paul
0
 

Author Comment

by:rmtogether
ID: 17927343
thanks PaulCaswell

I got it... by the way, can I ask you last question?

Since I might got couple sets of i , j (newt[N][i][j] != 0) to put in addpath(N, i, j), how can I design my addpath() to know each set of i, j and how many times ddpath(N, i, j) has called

<ps>
this is because my program need to know each set of i,j and also addpath()  will respond different actions every time called


----------------------------------------------------------
           if (newt[N][i][j] != 0)
           {    
               addpath(N, i, j);        
            }//end if


void addpath (int s, int i, int j)
{
  if( s == 0 )
  {
    printf("final path is %d%d%d : \n",s,i,j);
    printf("finish!!\n");
    return;
  }
   call other functions....
}
0
 
LVL 13

Assisted Solution

by:marchent
marchent earned 100 total points
ID: 17928272
>>how many times ddpath(N, i, j) has called
put some global variables
int counter = 0;
int pathN[100];//say maximum is 100
int pathI[100];
int pathJ[100];

and inside ddpath() add thease lines.
pathN[count] =s;
pathI[count] = i;
pathJ[count] =j;
count++;//increase the counter

to view the call informations use this function
void show()
{
   printf("Number of times ddpath called = %d\n",count);
   for(int i=0;i<count;i++)
      printf("Sets of values (%d,%d%d)\n",pathN[i],pathI[i],pathJ[i]);
}

~marchent~
0
 

Author Comment

by:rmtogether
ID: 17933433

thanks, marchent

since this is different question, I guess i should closed this one and open another.

I have open another question, base on this idea...could you please take a look. thanks in advance.

http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_22059132.html 
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

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…
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…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files 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.

856 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